1// Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
2// Copyright (C) 2015 Andrzej Krzemienski.
3//
4// Use, modification, and distribution is subject to the Boost Software
5// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7//
8// See http://www.boost.org/libs/optional for documentation.
9//
10// You are welcome to contact the author at:
11// akrzemi1@gmail.com
12
13#ifndef BOOST_OPTIONAL_DETAIL_OPTIONAL_RELOPS_AJK_03OCT2015_HPP
14#define BOOST_OPTIONAL_DETAIL_OPTIONAL_RELOPS_AJK_03OCT2015_HPP
15
16namespace boost {
17
18// optional's relational operators ( ==, !=, <, >, <=, >= ) have deep-semantics (compare values).
19// WARNING: This is UNLIKE pointers. Use equal_pointees()/less_pointess() in generic code instead.
20
21
22//
23// optional<T> vs optional<T> cases
24//
25
26template<class T>
27inline
28bool operator == ( optional<T> const& x, optional<T> const& y )
29{ return bool(x) && bool(y) ? *x == *y : bool(x) == bool(y); }
30
31template<class T>
32inline
33bool operator < ( optional<T> const& x, optional<T> const& y )
34{ return less_pointees(x,y); }
35
36template<class T>
37inline
38bool operator != ( optional<T> const& x, optional<T> const& y )
39{ return !( x == y ) ; }
40
41template<class T>
42inline
43bool operator > ( optional<T> const& x, optional<T> const& y )
44{ return y < x ; }
45
46template<class T>
47inline
48bool operator <= ( optional<T> const& x, optional<T> const& y )
49{ return !( y < x ) ; }
50
51template<class T>
52inline
53bool operator >= ( optional<T> const& x, optional<T> const& y )
54{ return !( x < y ) ; }
55
56
57//
58// optional<T> vs T cases
59//
60template<class T>
61inline
62bool operator == ( optional<T> const& x, T const& y )
63{ return equal_pointees(x, optional<T>(y)); }
64
65template<class T>
66inline
67bool operator < ( optional<T> const& x, T const& y )
68{ return less_pointees(x, optional<T>(y)); }
69
70template<class T>
71inline
72bool operator != ( optional<T> const& x, T const& y )
73{ return !( x == y ) ; }
74
75template<class T>
76inline
77bool operator > ( optional<T> const& x, T const& y )
78{ return y < x ; }
79
80template<class T>
81inline
82bool operator <= ( optional<T> const& x, T const& y )
83{ return !( y < x ) ; }
84
85template<class T>
86inline
87bool operator >= ( optional<T> const& x, T const& y )
88{ return !( x < y ) ; }
89
90//
91// T vs optional<T> cases
92//
93
94template<class T>
95inline
96bool operator == ( T const& x, optional<T> const& y )
97{ return equal_pointees( optional<T>(x), y ); }
98
99template<class T>
100inline
101bool operator < ( T const& x, optional<T> const& y )
102{ return less_pointees( optional<T>(x), y ); }
103
104template<class T>
105inline
106bool operator != ( T const& x, optional<T> const& y )
107{ return !( x == y ) ; }
108
109template<class T>
110inline
111bool operator > ( T const& x, optional<T> const& y )
112{ return y < x ; }
113
114template<class T>
115inline
116bool operator <= ( T const& x, optional<T> const& y )
117{ return !( y < x ) ; }
118
119template<class T>
120inline
121bool operator >= ( T const& x, optional<T> const& y )
122{ return !( x < y ) ; }
123
124
125//
126// optional<T> vs none cases
127//
128
129template<class T>
130inline
131bool operator == ( optional<T> const& x, none_t ) BOOST_NOEXCEPT
132{ return !x; }
133
134template<class T>
135inline
136bool operator < ( optional<T> const& x, none_t )
137{ return less_pointees(x,optional<T>() ); }
138
139template<class T>
140inline
141bool operator != ( optional<T> const& x, none_t ) BOOST_NOEXCEPT
142{ return bool(x); }
143
144template<class T>
145inline
146bool operator > ( optional<T> const& x, none_t y )
147{ return y < x ; }
148
149template<class T>
150inline
151bool operator <= ( optional<T> const& x, none_t y )
152{ return !( y < x ) ; }
153
154template<class T>
155inline
156bool operator >= ( optional<T> const& x, none_t y )
157{ return !( x < y ) ; }
158
159//
160// none vs optional<T> cases
161//
162
163template<class T>
164inline
165bool operator == ( none_t , optional<T> const& y ) BOOST_NOEXCEPT
166{ return !y; }
167
168template<class T>
169inline
170bool operator < ( none_t , optional<T> const& y )
171{ return less_pointees(optional<T>() ,y); }
172
173template<class T>
174inline
175bool operator != ( none_t, optional<T> const& y ) BOOST_NOEXCEPT
176{ return bool(y); }
177
178template<class T>
179inline
180bool operator > ( none_t x, optional<T> const& y )
181{ return y < x ; }
182
183template<class T>
184inline
185bool operator <= ( none_t x, optional<T> const& y )
186{ return !( y < x ) ; }
187
188template<class T>
189inline
190bool operator >= ( none_t x, optional<T> const& y )
191{ return !( x < y ) ; }
192
193} // namespace boost
194
195#endif // header guard
196
197

source code of include/boost/optional/detail/optional_relops.hpp