]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/describe/operators.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / describe / operators.hpp
1 #ifndef BOOST_DESCRIBE_OPERATORS_HPP_INCLUDED
2 #define BOOST_DESCRIBE_OPERATORS_HPP_INCLUDED
3
4 // Copyright 2020, 2021 Peter Dimov
5 // Distributed under the Boost Software License, Version 1.0.
6 // https://www.boost.org/LICENSE_1_0.txt
7
8 #include <boost/describe/detail/config.hpp>
9
10 #if defined(BOOST_DESCRIBE_CXX14)
11
12 #include <boost/describe/bases.hpp>
13 #include <boost/describe/members.hpp>
14 #include <boost/describe/modifiers.hpp>
15 #include <boost/mp11/algorithm.hpp>
16 #include <type_traits>
17 #include <iosfwd>
18
19 namespace boost
20 {
21 namespace describe
22 {
23
24 namespace detail
25 {
26
27 template<class T,
28 class Bd = describe_bases<T, mod_any_access>,
29 class Md = describe_members<T, mod_any_access>>
30 bool eq( T const& t1, T const& t2 )
31 {
32 bool r = true;
33
34 mp11::mp_for_each<Bd>([&](auto D){
35
36 using B = typename decltype(D)::type;
37 r = r && (B const&)t1 == (B const&)t2;
38
39 });
40
41 mp11::mp_for_each<Md>([&](auto D){
42
43 r = r && t1.*D.pointer == t2.*D.pointer;
44
45 });
46
47 return r;
48 }
49
50 template<class T,
51 class Bd = describe_bases<T, mod_any_access>,
52 class Md = describe_members<T, mod_any_access>>
53 bool lt( T const& t1, T const& t2 )
54 {
55 int r = 0;
56
57 mp11::mp_for_each<Bd>([&](auto D){
58
59 using B = typename decltype(D)::type;
60 if( r == 0 && (B const&)t1 < (B const&)t2 ) r = -1;
61 if( r == 0 && (B const&)t2 < (B const&)t1 ) r = +1;
62
63 });
64
65 mp11::mp_for_each<Md>([&](auto D){
66
67 if( r == 0 && t1.*D.pointer < t2.*D.pointer ) r = -1;
68 if( r == 0 && t2.*D.pointer < t1.*D.pointer ) r = +1;
69
70 });
71
72 return r < 0;
73 }
74
75 template<class Os, class T,
76 class Bd = describe_bases<T, mod_any_access>,
77 class Md = describe_members<T, mod_any_access>>
78 void print( Os& os, T const& t )
79 {
80 os << "{";
81
82 bool first = true;
83
84 mp11::mp_for_each<Bd>([&](auto D){
85
86 if( !first ) { os << ", "; }
87 first = false;
88
89 using B = typename decltype(D)::type;
90 os << (B const&)t;
91
92 });
93
94 mp11::mp_for_each<Md>([&](auto D){
95
96 if( !first ) { os << ", "; }
97 first = false;
98
99 os << "." << D.name << " = " << t.*D.pointer;
100
101 });
102
103 os << "}";
104 }
105
106 } // namespace detail
107
108 namespace operators
109 {
110
111 template<class T> std::enable_if_t<
112 has_describe_bases<T>::value && has_describe_members<T>::value && !std::is_union<T>::value, bool>
113 operator==( T const& t1, T const& t2 )
114 {
115 return detail::eq( t1, t2 );
116 }
117
118 template<class T> std::enable_if_t<
119 has_describe_bases<T>::value && has_describe_members<T>::value && !std::is_union<T>::value, bool>
120 operator!=( T const& t1, T const& t2 )
121 {
122 return !detail::eq( t1, t2 );
123 }
124
125 template<class T> std::enable_if_t<
126 has_describe_bases<T>::value && has_describe_members<T>::value && !std::is_union<T>::value, bool>
127 operator<( T const& t1, T const& t2 )
128 {
129 return detail::lt( t1, t2 );
130 }
131
132 template<class T> std::enable_if_t<
133 has_describe_bases<T>::value && has_describe_members<T>::value && !std::is_union<T>::value, bool>
134 operator>=( T const& t1, T const& t2 )
135 {
136 return !detail::lt( t1, t2 );
137 }
138
139 template<class T> std::enable_if_t<
140 has_describe_bases<T>::value && has_describe_members<T>::value && !std::is_union<T>::value, bool>
141 operator>( T const& t1, T const& t2 )
142 {
143 return detail::lt( t2, t1 );
144 }
145
146 template<class T> std::enable_if_t<
147 has_describe_bases<T>::value && has_describe_members<T>::value && !std::is_union<T>::value, bool>
148 operator<=( T const& t1, T const& t2 )
149 {
150 return !detail::lt( t2, t1 );
151 }
152
153 template<class T, class Ch, class Tr> std::enable_if_t<
154 has_describe_bases<T>::value && has_describe_members<T>::value && !std::is_union<T>::value,
155 std::basic_ostream<Ch, Tr>&>
156 operator<<( std::basic_ostream<Ch, Tr>& os, T const& t )
157 {
158 os.width( 0 );
159 detail::print( os, t );
160 return os;
161 }
162
163 } // namespace operators
164
165 } // namespace describe
166 } // namespace boost
167
168 #endif // defined(BOOST_DESCRIBE_CXX14)
169
170 #endif // #ifndef BOOST_DESCRIBE_OPERATORS_HPP_INCLUDED