Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/tr1/test/test_tuple_tricky.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 6.2 KB
Line 
1//  (C) Copyright John Maddock 2005.
2//  Use, modification and distribution are subject to the
3//  Boost Software License, Version 1.0. (See accompanying file
4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifdef TEST_STD_HEADERS
7#include <tuple>
8#include <functional>
9#include <utility>
10#else
11#include <boost/tr1/tuple.hpp>
12#include <boost/tr1/functional.hpp>
13#include <boost/tr1/utility.hpp>
14#endif
15
16#include <boost/static_assert.hpp>
17#include <boost/type_traits/is_same.hpp>
18
19#include "verify_return.hpp"
20
21struct strict_comparison1{};
22
23struct strict_comparison2
24{
25   strict_comparison2();
26   strict_comparison2(const strict_comparison1&);
27   strict_comparison2(const strict_comparison2&);
28
29   strict_comparison2& operator=(const strict_comparison2&);
30   strict_comparison2& operator=(const strict_comparison1&);
31};
32
33bool operator==(const strict_comparison1&, const strict_comparison1&);
34bool operator<(const strict_comparison1&, const strict_comparison1&);
35bool operator==(const strict_comparison2&, const strict_comparison2&);
36bool operator<(const strict_comparison2&, const strict_comparison2&);
37bool operator==(const strict_comparison1&, const strict_comparison2&);
38bool operator<(const strict_comparison1&, const strict_comparison2&);
39bool operator==(const strict_comparison2&, const strict_comparison1&);
40bool operator<(const strict_comparison2&, const strict_comparison1&);
41
42int main()
43{
44   std::tr1::tuple<int> t1a;
45   std::tr1::tuple<int> t1b(0);
46   std::tr1::tuple<int> t1c(t1b);
47   t1a = t1c;
48   std::tr1::tuple<int> t1d(std::tr1::tuple<short>(0));
49   t1a = std::tr1::tuple<short>(0);
50
51   std::tr1::tuple<int, long> t2a;
52   std::tr1::tuple<int, long> t2b(0, 0);
53   std::tr1::tuple<int, long> t2c(t2b);
54   t2a = t2c;
55   std::tr1::tuple<int, long> t2d(std::tr1::tuple<short, int>(0, 0));
56   t2a = std::tr1::tuple<short, int>(0, 0);
57   std::tr1::tuple<int, long> t2e(std::make_pair(0, 0L));
58   t2e = std::make_pair(0, 0L);
59 
60   // check implementation limits:
61   std::tr1::tuple<int, long, float, int, int, int, int, int, int> t10(0, 0, 0, 0, 0, 0, 0, 0, 0);
62
63   // make_tuple:
64   verify_return_type(std::tr1::make_tuple(0, 0, 0L), std::tr1::tuple<int, int, long>());
65   int i = 0;
66   std::tr1::tuple<int&, int, long> t3a(std::tr1::make_tuple(std::tr1::ref(i), 0, 0L));
67   verify_return_type(std::tr1::make_tuple(std::tr1::ref(i), 0, 0L), t3a);
68   std::tr1::tuple<const int&, int, long> t3b(std::tr1::make_tuple(std::tr1::cref(i), 0, 0L));
69   verify_return_type(std::tr1::make_tuple(std::tr1::cref(i), 0, 0L), t3b);
70   long j = 0;
71   std::tr1::tuple<int&, long&> tt(std::tr1::tie(i,j));
72
73   BOOST_STATIC_ASSERT((::std::tr1::tuple_size<std::tr1::tuple<int, long> >::value == 2));
74   BOOST_STATIC_ASSERT((::std::tr1::tuple_size<std::tr1::tuple<int, long, float, int, int, int, int, int, int> >::value == 9));
75
76   BOOST_STATIC_ASSERT((::boost::is_same< ::std::tr1::tuple_element<0, std::tr1::tuple<int, long> >::type, int>::value));
77   BOOST_STATIC_ASSERT((::boost::is_same< ::std::tr1::tuple_element<1, std::tr1::tuple<int, long> >::type, long>::value));
78   BOOST_STATIC_ASSERT((::boost::is_same< ::std::tr1::tuple_element<0, std::tr1::tuple<int&, long> >::type, int&>::value));
79   BOOST_STATIC_ASSERT((::boost::is_same< ::std::tr1::tuple_element<0, std::tr1::tuple<const int&, long> >::type, const int&>::value));
80
81   // get:
82   verify_return_type(&::std::tr1::get<0>(t1a), static_cast<int*>(0));
83   verify_return_type(&::std::tr1::get<1>(t2d), static_cast<long*>(0));
84   verify_return_type(&::std::tr1::get<0>(t3a), static_cast<int*>(0));
85   verify_return_type(&::std::tr1::get<0>(t3b), static_cast<const int*>(0));
86   const std::tr1::tuple<int>& cr1 = t1a;
87   verify_return_type(&::std::tr1::get<0>(cr1), static_cast<const int*>(0));
88   const std::tr1::tuple<int&, int, long>& cr2 = t3a;
89   verify_return_type(&::std::tr1::get<0>(cr2), static_cast<int*>(0));
90   const std::tr1::tuple<const int&, int, long>& cr3 = t3b;
91   // comparison:
92   verify_return_type(cr2 == cr3, false);
93   verify_return_type(cr2 != cr3, false);
94   verify_return_type(cr2 < cr3, false);
95   verify_return_type(cr2 > cr3, false);
96   verify_return_type(cr2 <= cr3, false);
97   verify_return_type(cr2 >= cr3, false);
98   // strict comparisons:
99   const std::tr1::tuple<strict_comparison1, strict_comparison2> comp1, comp2;
100   verify_return_type(comp1 == comp2, false);
101   verify_return_type(comp1 != comp2, false);
102   verify_return_type(comp1 < comp2, false);
103   verify_return_type(comp1 > comp2, false);
104   verify_return_type(comp1 <= comp2, false);
105   verify_return_type(comp1 >= comp2, false);
106   // test strict mixed comparisons
107   const std::tr1::tuple<strict_comparison2, strict_comparison1> comp3;
108   verify_return_type(comp1 == comp3, false);
109   verify_return_type(comp1 != comp3, false);
110   verify_return_type(comp1 < comp3, false);
111   verify_return_type(comp1 > comp3, false);
112   verify_return_type(comp1 <= comp3, false);
113   verify_return_type(comp1 >= comp3, false);
114   verify_return_type(comp3 == comp2, false);
115   verify_return_type(comp3 != comp2, false);
116   verify_return_type(comp3 < comp2, false);
117   verify_return_type(comp3 > comp2, false);
118   verify_return_type(comp3 <= comp2, false);
119   verify_return_type(comp3 >= comp2, false);
120   // test mixed construct and assign:
121   const std::tr1::tuple<strict_comparison1, double> cons1;
122   std::tr1::tuple<strict_comparison2, long double> cons2(cons1);
123   cons2 = cons1;
124   const std::pair<strict_comparison1, double> p1;
125   std::tr1::tuple<strict_comparison2, long double> cons3(p1);
126   cons3 = p1;
127
128   // pair interface:
129   BOOST_STATIC_ASSERT((::std::tr1::tuple_size<std::pair<int, long> >::value == 2));
130   BOOST_STATIC_ASSERT((::std::tr1::tuple_size<std::pair<int, float> >::value == 2));
131
132   BOOST_STATIC_ASSERT((::boost::is_same< ::std::tr1::tuple_element<0, std::pair<int, long> >::type, int>::value));
133   BOOST_STATIC_ASSERT((::boost::is_same< ::std::tr1::tuple_element<1, std::pair<int, long> >::type, long>::value));
134
135   std::pair<int, long> p2;
136   const std::pair<int, long>& p3 = p2;
137   verify_return_type(&std::tr1::get<0>(p2), static_cast<int*>(0));
138   verify_return_type(&std::tr1::get<1>(p2), static_cast<long*>(0));
139   verify_return_type(&std::tr1::get<0>(p3), static_cast<const int*>(0));
140   verify_return_type(&std::tr1::get<1>(p3), static_cast<const long*>(0));
141
142   return 0;
143}
144
Note: See TracBrowser for help on using the repository browser.