compare_pointees.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (C) 2003, Fernando Luis Cacciola Carballal.
  2. //
  3. // Use, modification, and distribution is subject to the Boost Software
  4. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/optional for documentation.
  8. //
  9. // You are welcome to contact the author at:
  10. // fernando_cacciola@hotmail.com
  11. //
  12. #ifndef BOOST_UTILITY_COMPARE_POINTEES_25AGO2003_HPP
  13. #define BOOST_UTILITY_COMPARE_POINTEES_25AGO2003_HPP
  14. #include<functional>
  15. namespace boost {
  16. // template<class OP> bool equal_pointees(OP const& x, OP const& y);
  17. // template<class OP> struct equal_pointees_t;
  18. //
  19. // Being OP a model of OptionalPointee (either a pointer or an optional):
  20. //
  21. // If both x and y have valid pointees, returns the result of (*x == *y)
  22. // If only one has a valid pointee, returns false.
  23. // If none have valid pointees, returns true.
  24. // No-throw
  25. template<class OptionalPointee>
  26. inline
  27. bool equal_pointees ( OptionalPointee const& x, OptionalPointee const& y )
  28. {
  29. return (!x) != (!y) ? false : ( !x ? true : (*x) == (*y) ) ;
  30. }
  31. template<class OptionalPointee>
  32. struct equal_pointees_t
  33. {
  34. typedef bool result_type;
  35. typedef OptionalPointee first_argument_type;
  36. typedef OptionalPointee second_argument_type;
  37. bool operator() ( OptionalPointee const& x, OptionalPointee const& y ) const
  38. { return equal_pointees(x,y) ; }
  39. } ;
  40. // template<class OP> bool less_pointees(OP const& x, OP const& y);
  41. // template<class OP> struct less_pointees_t;
  42. //
  43. // Being OP a model of OptionalPointee (either a pointer or an optional):
  44. //
  45. // If y has not a valid pointee, returns false.
  46. // ElseIf x has not a valid pointee, returns true.
  47. // ElseIf both x and y have valid pointees, returns the result of (*x < *y)
  48. // No-throw
  49. template<class OptionalPointee>
  50. inline
  51. bool less_pointees ( OptionalPointee const& x, OptionalPointee const& y )
  52. {
  53. return !y ? false : ( !x ? true : (*x) < (*y) ) ;
  54. }
  55. template<class OptionalPointee>
  56. struct less_pointees_t
  57. {
  58. typedef bool result_type;
  59. typedef OptionalPointee first_argument_type;
  60. typedef OptionalPointee second_argument_type;
  61. bool operator() ( OptionalPointee const& x, OptionalPointee const& y ) const
  62. { return less_pointees(x,y) ; }
  63. } ;
  64. } // namespace boost
  65. #endif