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