]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/tr1/test/test_tuple_tricky.cpp
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)
6 #ifdef TEST_STD_HEADERS
11 #include <boost/tr1/tuple.hpp>
12 #include <boost/tr1/functional.hpp>
13 #include <boost/tr1/utility.hpp>
16 #include <boost/static_assert.hpp>
17 #include <boost/type_traits/is_same.hpp>
19 #include "verify_return.hpp"
21 struct strict_comparison1
{};
23 struct strict_comparison2
26 strict_comparison2(const strict_comparison1
&);
27 strict_comparison2(const strict_comparison2
&);
29 strict_comparison2
& operator=(const strict_comparison2
&);
30 strict_comparison2
& operator=(const strict_comparison1
&);
33 bool operator==(const strict_comparison1
&, const strict_comparison1
&);
34 bool operator<(const strict_comparison1
&, const strict_comparison1
&);
35 bool operator==(const strict_comparison2
&, const strict_comparison2
&);
36 bool operator<(const strict_comparison2
&, const strict_comparison2
&);
37 bool operator==(const strict_comparison1
&, const strict_comparison2
&);
38 bool operator<(const strict_comparison1
&, const strict_comparison2
&);
39 bool operator==(const strict_comparison2
&, const strict_comparison1
&);
40 bool operator<(const strict_comparison2
&, const strict_comparison1
&);
44 std::tr1::tuple
<int> t1a
;
45 std::tr1::tuple
<int> t1b(0);
46 std::tr1::tuple
<int> t1c(t1b
);
48 std::tr1::tuple
<int> t1d(std::tr1::tuple
<short>(0));
49 t1a
= std::tr1::tuple
<short>(0);
51 std::tr1::tuple
<int, long> t2a
;
52 std::tr1::tuple
<int, long> t2b(0, 0);
53 std::tr1::tuple
<int, long> t2c(t2b
);
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);
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);
64 verify_return_type(std::tr1::make_tuple(0, 0, 0L), std::tr1::tuple
<int, int, long>());
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
);
71 std::tr1::tuple
<int&, long&> tt(std::tr1::tie(i
,j
));
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));
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
));
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
;
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
);
124 const std::pair
<strict_comparison1
, double> p1
;
125 std::tr1::tuple
<strict_comparison2
, long double> cons3(p1
);
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));
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
));
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));