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