// Copyright (C) 2003, 2008 Fernando Luis Cacciola Carballal. // Copyright (C) 2015, 2024 Andrzej Krzemienski. // // Use, modification, and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/optional for documentation. // // You are welcome to contact the author at: // akrzemi1@gmail.com #ifndef BOOST_OPTIONAL_DETAIL_OPTIONAL_RELOPS_AJK_03OCT2015_HPP #define BOOST_OPTIONAL_DETAIL_OPTIONAL_RELOPS_AJK_03OCT2015_HPP namespace boost { // optional's relational operators ( ==, !=, <, >, <=, >= ) have deep-semantics (compare values). // WARNING: This is UNLIKE pointers. Use equal_pointees()/less_pointees() in generic code instead, // to obtain the same semantic for pointers. // // optional vs optional cases // template inline bool operator == ( optional const& x, optional const& y ) { return bool(x) && bool(y) ? *x == *y : bool(x) == bool(y); } template inline bool operator < ( optional const& x, optional const& y ) { return !y ? false : (!x ? true : (*x) < (*y)); } template inline bool operator != ( optional const& x, optional const& y ) { return !( x == y ) ; } template inline bool operator > ( optional const& x, optional const& y ) { return y < x ; } template inline bool operator <= ( optional const& x, optional const& y ) { return !( y < x ) ; } template inline bool operator >= ( optional const& x, optional const& y ) { return !( x < y ) ; } // // optional vs T cases // template inline bool operator == ( optional const& x, T const& y ) { return x && (*x == y); } template inline bool operator < ( optional const& x, T const& y ) { return (!x) || (*x < y); } template inline bool operator != ( optional const& x, T const& y ) { return !( x == y ) ; } template inline bool operator > ( optional const& x, T const& y ) { return y < x ; } template inline bool operator <= ( optional const& x, T const& y ) { return !( y < x ) ; } template inline bool operator >= ( optional const& x, T const& y ) { return !( x < y ) ; } // // T vs optional cases // template inline bool operator == ( T const& x, optional const& y ) { return y && (x == *y); } template inline bool operator < ( T const& x, optional const& y ) { return y && (x < *y); } template inline bool operator != ( T const& x, optional const& y ) { return !( x == y ) ; } template inline bool operator > ( T const& x, optional const& y ) { return y < x ; } template inline bool operator <= ( T const& x, optional const& y ) { return !( y < x ) ; } template inline bool operator >= ( T const& x, optional const& y ) { return !( x < y ) ; } // // optional vs none cases // template inline bool operator == ( optional const& x, none_t ) BOOST_NOEXCEPT { return !x; } template inline bool operator < ( optional const&, none_t ) { return false; } template inline bool operator != ( optional const& x, none_t ) BOOST_NOEXCEPT { return bool(x); } template inline bool operator > ( optional const& x, none_t y ) { return y < x ; } template inline bool operator <= ( optional const& x, none_t y ) { return !( y < x ) ; } template inline bool operator >= ( optional const& x, none_t y ) { return !( x < y ) ; } // // none vs optional cases // template inline bool operator == ( none_t , optional const& y ) BOOST_NOEXCEPT { return !y; } template inline bool operator < ( none_t , optional const& y ) { return bool(y); } template inline bool operator != ( none_t, optional const& y ) BOOST_NOEXCEPT { return bool(y); } template inline bool operator > ( none_t x, optional const& y ) { return y < x ; } template inline bool operator <= ( none_t x, optional const& y ) { return !( y < x ) ; } template inline bool operator >= ( none_t x, optional const& y ) { return !( x < y ) ; } } // namespace boost #endif // header guard