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