]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/system/test/result_eq.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / system / test / result_eq.cpp
1 // Copyright 2017, 2021 Peter Dimov.
2 // Distributed under the Boost Software License, Version 1.0.
3 // https://www.boost.org/LICENSE_1_0.txt
4
5 #include <boost/system/result.hpp>
6 #include <boost/core/lightweight_test.hpp>
7 #include <iosfwd>
8 #include <cerrno>
9
10 using namespace boost::system;
11
12 struct X
13 {
14 static int instances;
15
16 int v_;
17
18 explicit X( int v ): v_( v ) { ++instances; }
19
20 X( X const& r ) = delete;
21 X( X&& r ): v_( r.v_ ) { r.v_ = 0; ++instances; }
22
23 X& operator=( X const& ) = delete;
24
25 X& operator=( X&& r )
26 {
27 v_ = r.v_;
28 r.v_ = 0;
29
30 return *this;
31 }
32
33 ~X() { --instances; }
34 };
35
36 bool operator==( X const & x1, X const & x2 )
37 {
38 return x1.v_ == x2.v_;
39 }
40
41 std::ostream& operator<<( std::ostream& os, X const & x )
42 {
43 os << "X:" << x.v_;
44 return os;
45 }
46
47 int X::instances = 0;
48
49 struct Y
50 {
51 static int instances;
52
53 int v_;
54
55 explicit Y( int v = 0 ): v_( v ) { ++instances; }
56
57 Y( Y const& r ) noexcept: v_( r.v_ ) { ++instances; }
58 Y( Y&& r ) noexcept: v_( r.v_ ) { r.v_ = 0; ++instances; }
59
60 Y& operator=( Y const& ) = default;
61
62 Y& operator=( Y&& r )
63 {
64 v_ = r.v_;
65 r.v_ = 0;
66
67 return *this;
68 }
69
70 ~Y() { --instances; }
71 };
72
73 bool operator==( Y const & y1, Y const & y2 )
74 {
75 return y1.v_ == y2.v_;
76 }
77
78 std::ostream& operator<<( std::ostream& os, Y const & y )
79 {
80 os << "Y:" << y.v_;
81 return os;
82 }
83
84 int Y::instances = 0;
85
86 int main()
87 {
88 {
89 result<int> r1( 1 );
90 result<int> r2( 2 );
91
92 BOOST_TEST_EQ( r1, r1 );
93 BOOST_TEST_NE( r1, r2 );
94 }
95
96 {
97 result<int> r1( 1, generic_category() );
98 result<int> r2( 2, generic_category() );
99
100 BOOST_TEST_EQ( r1, r1 );
101 BOOST_TEST_NE( r1, r2 );
102 }
103
104 {
105 result<int> r1( 1 );
106 result<int> r2( 2, generic_category() );
107
108 BOOST_TEST_EQ( r1, r1 );
109 BOOST_TEST_NE( r1, r2 );
110 }
111
112 {
113 result<X, Y> r1( in_place_value, 1 );
114 result<X, Y> r2( in_place_value, 2 );
115
116 BOOST_TEST_EQ( r1, r1 );
117 BOOST_TEST_NE( r1, r2 );
118 }
119
120 {
121 result<X, Y> r1( in_place_error, 1 );
122 result<X, Y> r2( in_place_error, 2 );
123
124 BOOST_TEST_EQ( r1, r1 );
125 BOOST_TEST_NE( r1, r2 );
126 }
127
128 {
129 result<X, Y> r1( in_place_value, 1 );
130 result<X, Y> r2( in_place_error, 2 );
131
132 BOOST_TEST_EQ( r1, r1 );
133 BOOST_TEST_NE( r1, r2 );
134 }
135
136 {
137 result<void> r1;
138 result<void> r2;
139
140 BOOST_TEST_EQ( r1, r1 );
141 BOOST_TEST_EQ( r1, r2 );
142 }
143
144 {
145 result<void> r1( 1, generic_category() );
146 result<void> r2( 2, generic_category() );
147
148 BOOST_TEST_EQ( r1, r1 );
149 BOOST_TEST_NE( r1, r2 );
150 }
151
152 return boost::report_errors();
153 }