]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // | |
3 | // (C) Copyright Ion Gaztanaga 2014-2014. Distributed under the Boost | |
4 | // Software License, Version 1.0. (See accompanying file | |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | // | |
7 | // See http://www.boost.org/libs/container for documentation. | |
8 | // | |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef BOOST_CONTAINER_DETAIL_COMPARE_FUNCTORS_HPP | |
12 | #define BOOST_CONTAINER_DETAIL_COMPARE_FUNCTORS_HPP | |
13 | ||
14 | #ifndef BOOST_CONFIG_HPP | |
15 | # include <boost/config.hpp> | |
16 | #endif | |
17 | ||
18 | #if defined(BOOST_HAS_PRAGMA_ONCE) | |
19 | # pragma once | |
20 | #endif | |
21 | ||
92f5a8d4 | 22 | #include <boost/intrusive/detail/ebo_functor_holder.hpp> |
20effc67 | 23 | #include <boost/container/detail/workaround.hpp> |
92f5a8d4 | 24 | |
7c673cae FG |
25 | namespace boost { |
26 | namespace container { | |
27 | ||
92f5a8d4 | 28 | template<class ValueType> |
7c673cae FG |
29 | class equal_to_value |
30 | { | |
92f5a8d4 | 31 | typedef ValueType value_type; |
7c673cae FG |
32 | const value_type &t_; |
33 | ||
34 | public: | |
35 | explicit equal_to_value(const value_type &t) | |
36 | : t_(t) | |
37 | {} | |
38 | ||
39 | bool operator()(const value_type &t)const | |
40 | { return t_ == t; } | |
41 | }; | |
42 | ||
92f5a8d4 | 43 | template<class Node, class Pred, class Ret = bool> |
7c673cae FG |
44 | struct value_to_node_compare |
45 | : Pred | |
46 | { | |
47 | typedef Pred predicate_type; | |
48 | typedef Node node_type; | |
49 | ||
50 | value_to_node_compare() | |
51 | : Pred() | |
52 | {} | |
53 | ||
54 | explicit value_to_node_compare(Pred pred) | |
55 | : Pred(pred) | |
56 | {} | |
57 | ||
92f5a8d4 | 58 | Ret operator()(const Node &a, const Node &b) const |
7c673cae FG |
59 | { return static_cast<const Pred&>(*this)(a.get_data(), b.get_data()); } |
60 | ||
92f5a8d4 | 61 | Ret operator()(const Node &a) const |
7c673cae FG |
62 | { return static_cast<const Pred&>(*this)(a.get_data()); } |
63 | ||
92f5a8d4 | 64 | Ret operator()(const Node &a, const Node &b) |
7c673cae FG |
65 | { return static_cast<Pred&>(*this)(a.get_data(), b.get_data()); } |
66 | ||
92f5a8d4 | 67 | Ret operator()(const Node &a) |
7c673cae FG |
68 | { return static_cast<Pred&>(*this)(a.get_data()); } |
69 | ||
70 | predicate_type & predicate() { return static_cast<predicate_type&>(*this); } | |
71 | const predicate_type & predicate() const { return static_cast<predicate_type&>(*this); } | |
72 | }; | |
73 | ||
92f5a8d4 TL |
74 | template<class KeyPred, class KeyOfValue, class Node, class Ret = bool> |
75 | struct key_node_pred | |
76 | : public boost::intrusive::detail::ebo_functor_holder<KeyPred> | |
77 | { | |
78 | BOOST_CONTAINER_FORCEINLINE explicit key_node_pred(const KeyPred &comp) | |
79 | : base_t(comp) | |
80 | {} | |
81 | ||
82 | typedef boost::intrusive::detail::ebo_functor_holder<KeyPred> base_t; | |
83 | typedef KeyPred key_predicate; | |
84 | typedef KeyOfValue key_of_value; | |
85 | typedef typename KeyOfValue::type key_type; | |
86 | ||
87 | ||
88 | BOOST_CONTAINER_FORCEINLINE static const key_type &key_from(const Node &n) | |
89 | { | |
90 | return key_of_value()(n.get_data()); | |
91 | } | |
92 | ||
93 | template <class T> | |
94 | BOOST_CONTAINER_FORCEINLINE static const T & | |
95 | key_from(const T &t) | |
96 | { return t; } | |
97 | ||
98 | BOOST_CONTAINER_FORCEINLINE const key_predicate &key_pred() const | |
99 | { return static_cast<const key_predicate &>(*this); } | |
100 | ||
101 | BOOST_CONTAINER_FORCEINLINE key_predicate &key_pred() | |
102 | { return static_cast<key_predicate &>(*this); } | |
103 | ||
104 | BOOST_CONTAINER_FORCEINLINE Ret operator()(const key_type &key) const | |
105 | { return this->key_pred()(key); } | |
106 | ||
107 | template<class U> | |
108 | BOOST_CONTAINER_FORCEINLINE Ret operator()(const U &nonkey) const | |
109 | { return this->key_pred()(this->key_from(nonkey)); } | |
110 | ||
111 | BOOST_CONTAINER_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const | |
112 | { return this->key_pred()(key1, key2); } | |
113 | ||
114 | template<class U> | |
115 | BOOST_CONTAINER_FORCEINLINE bool operator()(const key_type &key1, const U &nonkey2) const | |
116 | { return this->key_pred()(key1, this->key_from(nonkey2)); } | |
117 | ||
118 | template<class U> | |
119 | BOOST_CONTAINER_FORCEINLINE bool operator()(const U &nonkey1, const key_type &key2) const | |
120 | { return this->key_pred()(this->key_from(nonkey1), key2); } | |
121 | ||
122 | template<class U, class V> | |
123 | BOOST_CONTAINER_FORCEINLINE bool operator()(const U &nonkey1, const V &nonkey2) const | |
124 | { return this->key_pred()(this->key_from(nonkey1), this->key_from(nonkey2)); } | |
125 | }; | |
126 | ||
127 | ||
7c673cae FG |
128 | } //namespace container { |
129 | } //namespace boost { | |
130 | ||
131 | #endif //BOOST_CONTAINER_DETAIL_COMPARE_FUNCTORS_HPP |