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
15 #include<functional>
16
17 namespace boost {
18
19 // template<class OP> bool equal_pointees(OP const& x, OP const& y);
20 // template<class OP> struct equal_pointees_t;
21 //
22 // Being OP a model of OptionalPointee (either a pointer or an optional):
23 //
24 // If both x and y have valid pointees, returns the result of (*x == *y)
25 // If only one has a valid pointee, returns false.
26 // If none have valid pointees, returns true.
27 // No-throw
28 template<class OptionalPointee>
29 inline
equal_pointees(OptionalPointee const & x,OptionalPointee const & y)30 bool equal_pointees ( OptionalPointee const& x, OptionalPointee const& y )
31 {
32 return (!x) != (!y) ? false : ( !x ? true : (*x) == (*y) ) ;
33 }
34
35 template<class OptionalPointee>
36 struct equal_pointees_t
37 {
38 typedef bool result_type;
39 typedef OptionalPointee first_argument_type;
40 typedef OptionalPointee second_argument_type;
41
operator ()boost::equal_pointees_t42 bool operator() ( OptionalPointee const& x, OptionalPointee const& y ) const
43 { return equal_pointees(x,y) ; }
44 } ;
45
46 // template<class OP> bool less_pointees(OP const& x, OP const& y);
47 // template<class OP> struct less_pointees_t;
48 //
49 // Being OP a model of OptionalPointee (either a pointer or an optional):
50 //
51 // If y has not a valid pointee, returns false.
52 // ElseIf x has not a valid pointee, returns true.
53 // ElseIf both x and y have valid pointees, returns the result of (*x < *y)
54 // No-throw
55 template<class OptionalPointee>
56 inline
less_pointees(OptionalPointee const & x,OptionalPointee const & y)57 bool less_pointees ( OptionalPointee const& x, OptionalPointee const& y )
58 {
59 return !y ? false : ( !x ? true : (*x) < (*y) ) ;
60 }
61
62 template<class OptionalPointee>
63 struct less_pointees_t
64 {
65 typedef bool result_type;
66 typedef OptionalPointee first_argument_type;
67 typedef OptionalPointee second_argument_type;
68
operator ()boost::less_pointees_t69 bool operator() ( OptionalPointee const& x, OptionalPointee const& y ) const
70 { return less_pointees(x,y) ; }
71 } ;
72
73 } // namespace boost
74
75 #endif
76
77