Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / bimap / container_adaptor / detail / comparison_adaptor.hpp
1 // Boost.Bimap
2 //
3 // Copyright (c) 2006-2007 Matias Capeletto
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8
9 /// \file container_adaptor/detail/comparison_adaptor.hpp
10 /// \brief Comparison adaptor.
11
12 #ifndef BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_COMPARISON_ADAPTOR_HPP
13 #define BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_COMPARISON_ADAPTOR_HPP
14
15 #if defined(_MSC_VER) && (_MSC_VER>=1200)
16 #pragma once
17 #endif
18
19 #include <boost/config.hpp>
20
21 #include <boost/call_traits.hpp>
22 #include <functional>
23
24 namespace boost {
25 namespace bimaps {
26 namespace container_adaptor {
27 namespace detail {
28
29 /// \brief Comparison adaptor
30 /**
31
32 A simple comparison adaptor.
33                                                                                     **/
34
35 template < class Compare, class NewType, class Converter >
36 struct comparison_adaptor : std::binary_function<NewType,NewType,bool>
37 {
38     comparison_adaptor( const Compare & comp, const Converter & conv)
39         : compare(comp), converter(conv) {}
40
41     bool operator()( BOOST_DEDUCED_TYPENAME call_traits<NewType>::param_type x,
42                      BOOST_DEDUCED_TYPENAME call_traits<NewType>::param_type y) const
43     {
44         return compare( converter(x), converter(y) );
45     }
46
47     private:
48     Compare     compare;
49     Converter   converter;
50 };
51
52 template < class Compare, class NewType, class Converter >
53 struct compatible_comparison_adaptor : std::binary_function<NewType,NewType,bool>
54 {
55     compatible_comparison_adaptor( const Compare & comp, const Converter & conv)
56         : compare(comp), converter(conv) {}
57
58     template< class CompatibleTypeLeft, class CompatibleTypeRight >
59     bool operator()( const CompatibleTypeLeft  & x,
60                      const CompatibleTypeRight & y) const
61     {
62         return compare( converter(x), converter(y) );
63     }
64
65     private:
66     Compare     compare;
67     Converter   converter;
68 };
69
70
71 /// \brief Unary Check adaptor
72 /**
73
74 A simple unary check adaptor.
75                                                                                     **/
76
77 template < class Compare, class NewType, class Converter >
78 struct unary_check_adaptor : std::unary_function<NewType,bool>
79 {
80     unary_check_adaptor( const Compare & comp, const Converter & conv ) :
81         compare(comp), converter(conv) {}
82
83     bool operator()( BOOST_DEDUCED_TYPENAME call_traits<NewType>::param_type x) const
84     {
85         return compare( converter(x) );
86     }
87
88     private:
89     Compare   compare;
90     Converter converter;
91 };
92
93 } // namespace detail
94 } // namespace container_adaptor
95 } // namespace bimaps
96 } // namespace boost
97
98
99 #endif // BOOST_BIMAP_CONTAINER_ADAPTOR_DETAIL_COMPARISON_ADAPTOR_HPP
100
101