1
2 // Copyright 2017 Peter Dimov.
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 //
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
8
9 #include <boost/variant2/variant.hpp>
10 #include <boost/core/lightweight_test.hpp>
11 #include <boost/core/lightweight_test_trait.hpp>
12 #include <type_traits>
13 #include <utility>
14 #include <string>
15
16 using namespace boost::variant2;
17
18 struct X
19 {
20 };
21
operator <(X const &,X const &)22 inline bool operator<( X const&, X const& ) { return false; }
operator >(X const &,X const &)23 inline bool operator>( X const&, X const& ) { return false; }
operator <=(X const &,X const &)24 inline bool operator<=( X const&, X const& ) { return false; }
operator >=(X const &,X const &)25 inline bool operator>=( X const&, X const& ) { return false; }
26
27 #define TEST_EQ( v1, v2 ) \
28 BOOST_TEST_NOT( v1 < v2 ); \
29 BOOST_TEST_NOT( v1 > v2 ); \
30 BOOST_TEST( v1 <= v2 ); \
31 BOOST_TEST( v1 >= v2 );
32
33 #define TEST_LE( v1, v3 ) \
34 BOOST_TEST( v1 < v3 ); \
35 BOOST_TEST( v3 > v1 ); \
36 BOOST_TEST_NOT( v1 > v3 ); \
37 BOOST_TEST_NOT( v3 < v1 ); \
38 BOOST_TEST( v1 <= v3 ); \
39 BOOST_TEST( v3 >= v1 ); \
40 BOOST_TEST_NOT( v1 >= v3 ); \
41 BOOST_TEST_NOT( v3 <= v1 );
42
main()43 int main()
44 {
45 {
46 variant<int> v1, v2, v3( 1 ), v4( 1 );
47
48 TEST_EQ( v1, v2 )
49 TEST_LE( v1, v3 )
50 TEST_EQ( v3, v4 )
51 }
52
53 {
54 variant<int, float> v1, v2, v3( 1 ), v4( 1 ), v5( 3.14f ), v6( 3.14f );
55
56 TEST_EQ( v1, v2 )
57 TEST_LE( v1, v3 )
58 TEST_EQ( v3, v4 )
59 TEST_LE( v1, v5 )
60 TEST_LE( v3, v5 )
61 TEST_EQ( v5, v6 )
62 }
63
64 {
65 variant<int, int, float> v1, v2, v3( in_place_index_t<1>{} ), v4( in_place_index_t<1>{} ), v5( 3.14f ), v6( 3.14f );
66
67 TEST_EQ( v1, v2 )
68 TEST_LE( v1, v3 )
69 TEST_EQ( v3, v4 )
70 TEST_LE( v1, v5 )
71 TEST_LE( v3, v5 )
72 TEST_EQ( v5, v6 )
73 }
74
75 {
76 variant<X> v1, v2;
77
78 BOOST_TEST_NOT( v1 < v2 );
79 BOOST_TEST_NOT( v1 > v2 );
80 BOOST_TEST_NOT( v1 <= v2 );
81 BOOST_TEST_NOT( v1 >= v2 );
82 }
83
84 return boost::report_errors();
85 }
86