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