williamr@2: // Copyright (C) 2003, Fernando Luis Cacciola Carballal. williamr@2: // williamr@2: // Use, modification, and distribution is subject to the Boost Software williamr@2: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at williamr@2: // http://www.boost.org/LICENSE_1_0.txt) williamr@2: // williamr@2: // See http://www.boost.org/lib/optional for documentation. williamr@2: // williamr@2: // You are welcome to contact the author at: williamr@2: // fernando_cacciola@hotmail.com williamr@2: // williamr@2: #ifndef BOOST_UTILITY_COMPARE_POINTEES_25AGO2003_HPP williamr@2: #define BOOST_UTILITY_COMPARE_POINTEES_25AGO2003_HPP williamr@2: williamr@2: #include williamr@2: williamr@2: namespace boost { williamr@2: williamr@2: // template bool equal_pointees(OP const& x, OP const& y); williamr@2: // template struct equal_pointees_t; williamr@2: // williamr@2: // Being OP a model of OptionalPointee (either a pointer or an optional): williamr@2: // williamr@2: // If both x and y have valid pointees, returns the result of (*x == *y) williamr@2: // If only one has a valid pointee, returns false. williamr@2: // If none have valid pointees, returns true. williamr@2: // No-throw williamr@2: template williamr@2: inline williamr@2: bool equal_pointees ( OptionalPointee const& x, OptionalPointee const& y ) williamr@2: { williamr@2: return (!x) != (!y) ? false : ( !x ? true : (*x) == (*y) ) ; williamr@2: } williamr@2: williamr@2: template williamr@2: struct equal_pointees_t : std::binary_function williamr@2: { williamr@2: bool operator() ( OptionalPointee const& x, OptionalPointee const& y ) const williamr@2: { return equal_pointees(x,y) ; } williamr@2: } ; williamr@2: williamr@2: // template bool less_pointees(OP const& x, OP const& y); williamr@2: // template struct less_pointees_t; williamr@2: // williamr@2: // Being OP a model of OptionalPointee (either a pointer or an optional): williamr@2: // williamr@2: // If y has not a valid pointee, returns false. williamr@2: // ElseIf x has not a valid pointee, returns true. williamr@2: // ElseIf both x and y have valid pointees, returns the result of (*x < *y) williamr@2: // No-throw williamr@2: template williamr@2: inline williamr@2: bool less_pointees ( OptionalPointee const& x, OptionalPointee const& y ) williamr@2: { williamr@2: return !y ? false : ( !x ? true : (*x) < (*y) ) ; williamr@2: } williamr@2: williamr@2: template williamr@2: struct less_pointees_t : std::binary_function williamr@2: { williamr@2: bool operator() ( OptionalPointee const& x, OptionalPointee const& y ) const williamr@2: { return less_pointees(x,y) ; } williamr@2: } ; williamr@2: williamr@2: } // namespace boost williamr@2: williamr@2: #endif williamr@2: