Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:53:34

0001 // Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal.
0002 // Copyright (C) 2015, 2024 Andrzej Krzemienski.
0003 //
0004 // Use, modification, and distribution is subject to the Boost Software
0005 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // See http://www.boost.org/libs/optional for documentation.
0009 //
0010 // You are welcome to contact the author at:
0011 //  akrzemi1@gmail.com
0012 
0013 #ifndef BOOST_OPTIONAL_DETAIL_OPTIONAL_RELOPS_AJK_03OCT2015_HPP
0014 #define BOOST_OPTIONAL_DETAIL_OPTIONAL_RELOPS_AJK_03OCT2015_HPP
0015 
0016 namespace boost {
0017 
0018 // optional's relational operators ( ==, !=, <, >, <=, >= ) have deep-semantics (compare values).
0019 // WARNING: This is UNLIKE pointers. Use equal_pointees()/less_pointees() in generic code instead,
0020 // to obtain the same semantic for pointers.
0021 
0022 
0023 //
0024 // optional<T> vs optional<T> cases
0025 //
0026 
0027 template<class T>
0028 inline
0029 bool operator == ( optional<T> const& x, optional<T> const& y )
0030 { return bool(x) && bool(y) ? *x == *y : bool(x) == bool(y); }
0031 
0032 template<class T>
0033 inline
0034 bool operator < ( optional<T> const& x, optional<T> const& y )
0035 { return !y ? false : (!x ? true : (*x) < (*y)); }
0036 
0037 template<class T>
0038 inline
0039 bool operator != ( optional<T> const& x, optional<T> const& y )
0040 { return !( x == y ) ; }
0041 
0042 template<class T>
0043 inline
0044 bool operator > ( optional<T> const& x, optional<T> const& y )
0045 { return y < x ; }
0046 
0047 template<class T>
0048 inline
0049 bool operator <= ( optional<T> const& x, optional<T> const& y )
0050 { return !( y < x ) ; }
0051 
0052 template<class T>
0053 inline
0054 bool operator >= ( optional<T> const& x, optional<T> const& y )
0055 { return !( x < y ) ; }
0056 
0057 
0058 //
0059 // optional<T> vs T cases
0060 //
0061 template<class T>
0062 inline
0063 bool operator == ( optional<T> const& x, T const& y )
0064 { return x && (*x == y); }
0065 
0066 template<class T>
0067 inline
0068 bool operator < ( optional<T> const& x, T const& y )
0069 { return (!x) || (*x < y); }
0070 
0071 template<class T>
0072 inline
0073 bool operator != ( optional<T> const& x, T const& y )
0074 { return !( x == y ) ; }
0075 
0076 template<class T>
0077 inline
0078 bool operator > ( optional<T> const& x, T const& y )
0079 { return y < x ; }
0080 
0081 template<class T>
0082 inline
0083 bool operator <= ( optional<T> const& x, T const& y )
0084 { return !( y < x ) ; }
0085 
0086 template<class T>
0087 inline
0088 bool operator >= ( optional<T> const& x, T const& y )
0089 { return !( x < y ) ; }
0090 
0091 //
0092 // T vs optional<T> cases
0093 //
0094 
0095 template<class T>
0096 inline
0097 bool operator == ( T const& x, optional<T> const& y )
0098 { return y && (x == *y); }
0099 
0100 template<class T>
0101 inline
0102 bool operator < ( T const& x, optional<T> const& y )
0103 { return y && (x < *y); }
0104 
0105 template<class T>
0106 inline
0107 bool operator != ( T const& x, optional<T> const& y )
0108 { return !( x == y ) ; }
0109 
0110 template<class T>
0111 inline
0112 bool operator > ( T const& x, optional<T> const& y )
0113 { return y < x ; }
0114 
0115 template<class T>
0116 inline
0117 bool operator <= ( T const& x, optional<T> const& y )
0118 { return !( y < x ) ; }
0119 
0120 template<class T>
0121 inline
0122 bool operator >= ( T const& x, optional<T> const& y )
0123 { return !( x < y ) ; }
0124 
0125 
0126 //
0127 // optional<T> vs none cases
0128 //
0129 
0130 template<class T>
0131 inline
0132 bool operator == ( optional<T> const& x, none_t ) BOOST_NOEXCEPT
0133 { return !x; }
0134 
0135 template<class T>
0136 inline
0137 bool operator < ( optional<T> const&, none_t )
0138 { return false; }
0139 
0140 template<class T>
0141 inline
0142 bool operator != ( optional<T> const& x, none_t ) BOOST_NOEXCEPT
0143 { return bool(x); }
0144 
0145 template<class T>
0146 inline
0147 bool operator > ( optional<T> const& x, none_t y )
0148 { return y < x ; }
0149 
0150 template<class T>
0151 inline
0152 bool operator <= ( optional<T> const& x, none_t y )
0153 { return !( y < x ) ; }
0154 
0155 template<class T>
0156 inline
0157 bool operator >= ( optional<T> const& x, none_t y )
0158 { return !( x < y ) ; }
0159 
0160 //
0161 // none vs optional<T> cases
0162 //
0163 
0164 template<class T>
0165 inline
0166 bool operator == ( none_t , optional<T> const& y ) BOOST_NOEXCEPT
0167 { return !y; }
0168 
0169 template<class T>
0170 inline
0171 bool operator < ( none_t , optional<T> const& y )
0172 { return bool(y); }
0173 
0174 template<class T>
0175 inline
0176 bool operator != ( none_t, optional<T> const& y ) BOOST_NOEXCEPT
0177 { return bool(y); }
0178 
0179 template<class T>
0180 inline
0181 bool operator > ( none_t x, optional<T> const& y )
0182 { return y < x ; }
0183 
0184 template<class T>
0185 inline
0186 bool operator <= ( none_t x, optional<T> const& y )
0187 { return !( y < x ) ; }
0188 
0189 template<class T>
0190 inline
0191 bool operator >= ( none_t x, optional<T> const& y )
0192 { return !( x < y ) ; }
0193 
0194 } // namespace boost
0195 
0196 #endif // header guard