]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/intrusive/include/boost/intrusive/detail/tree_value_compare.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / intrusive / include / boost / intrusive / detail / tree_value_compare.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2015-2015. 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 #ifndef BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP
11 #define BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP
12
13 #ifndef BOOST_CONFIG_HPP
14 # include <boost/config.hpp>
15 #endif
16
17 #if defined(BOOST_HAS_PRAGMA_ONCE)
18 # pragma once
19 #endif
20
21 #include <boost/intrusive/detail/workaround.hpp>
22 #include <boost/intrusive/detail/mpl.hpp>
23 #include <boost/intrusive/detail/ebo_functor_holder.hpp>
24 #include <boost/intrusive/pointer_traits.hpp>
25
26 namespace boost{
27 namespace intrusive{
28
29 //Needed to support smart references to value types
30 template <class From, class ValuePtr>
31 struct disable_if_smartref_to
32 : detail::disable_if_c
33 < detail::is_same
34 <From, typename pointer_traits
35 <ValuePtr>
36 ::reference>::value
37 || detail::is_same
38 <From, typename pointer_traits
39 < typename pointer_rebind
40 <ValuePtr, const typename pointer_element<ValuePtr>::type>::type>
41 ::reference>::value
42 >
43 {};
44
45 //This function object takes a KeyCompare function object
46 //and compares values that contains keys using KeyOfValue
47 template< class ValuePtr, class KeyCompare, class KeyOfValue
48 , bool = boost::intrusive::detail::is_same<typename pointer_element<ValuePtr>::type, typename KeyOfValue::type>::value >
49 struct tree_value_compare
50 : public boost::intrusive::detail::ebo_functor_holder<KeyCompare>
51 {
52 typedef typename pointer_element<ValuePtr>::type value_type;
53 typedef KeyCompare key_compare;
54 typedef KeyOfValue key_of_value;
55 typedef typename KeyOfValue::type key_type;
56
57 typedef boost::intrusive::detail::ebo_functor_holder<KeyCompare> base_t;
58
59 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare()
60 : base_t()
61 {}
62
63 BOOST_INTRUSIVE_FORCEINLINE explicit tree_value_compare(const key_compare &kcomp)
64 : base_t(kcomp)
65 {}
66
67 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare (const tree_value_compare &x)
68 : base_t(x.base_t::get())
69 {}
70
71 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const tree_value_compare &x)
72 { this->base_t::get() = x.base_t::get(); return *this; }
73
74 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const key_compare &x)
75 { this->base_t::get() = x; return *this; }
76
77 BOOST_INTRUSIVE_FORCEINLINE const key_compare &key_comp() const
78 { return static_cast<const key_compare &>(*this); }
79
80 BOOST_INTRUSIVE_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const
81 { return this->key_comp()(key1, key2); }
82
83 BOOST_INTRUSIVE_FORCEINLINE bool operator()(const value_type &value1, const value_type &value2) const
84 { return this->key_comp()(KeyOfValue()(value1), KeyOfValue()(value2)); }
85
86 BOOST_INTRUSIVE_FORCEINLINE bool operator()(const key_type &key1, const value_type &value2) const
87 { return this->key_comp()(key1, KeyOfValue()(value2)); }
88
89 BOOST_INTRUSIVE_FORCEINLINE bool operator()(const value_type &value1, const key_type &key2) const
90 { return this->key_comp()(KeyOfValue()(value1), key2); }
91
92 template<class U>
93 BOOST_INTRUSIVE_FORCEINLINE bool operator()( const key_type &key1, const U &nonkey2
94 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
95 { return this->key_comp()(key1, nonkey2); }
96
97 template<class U>
98 BOOST_INTRUSIVE_FORCEINLINE bool operator()( const U &nonkey1, const key_type &key2
99 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
100 { return this->key_comp()(nonkey1, key2); }
101
102 template<class U>
103 BOOST_INTRUSIVE_FORCEINLINE bool operator()( const value_type &value1, const U &nonvalue2
104 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
105 { return this->key_comp()(KeyOfValue()(value1), nonvalue2); }
106
107 template<class U>
108 BOOST_INTRUSIVE_FORCEINLINE bool operator()( const U &nonvalue1, const value_type &value2
109 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
110 { return this->key_comp()(nonvalue1, KeyOfValue()(value2)); }
111 };
112
113 template<class ValuePtr, class KeyCompare, class KeyOfValue>
114 struct tree_value_compare<ValuePtr, KeyCompare, KeyOfValue, true>
115 : public boost::intrusive::detail::ebo_functor_holder<KeyCompare>
116 {
117 typedef typename pointer_element<ValuePtr>::type value_type;
118 typedef KeyCompare key_compare;
119 typedef KeyOfValue key_of_value;
120 typedef typename KeyOfValue::type key_type;
121
122 typedef boost::intrusive::detail::ebo_functor_holder<KeyCompare> base_t;
123
124
125 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare()
126 : base_t()
127 {}
128
129 BOOST_INTRUSIVE_FORCEINLINE explicit tree_value_compare(const key_compare &kcomp)
130 : base_t(kcomp)
131 {}
132
133 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare (const tree_value_compare &x)
134 : base_t(x.base_t::get())
135 {}
136
137 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const tree_value_compare &x)
138 { this->base_t::get() = x.base_t::get(); return *this; }
139
140 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const key_compare &x)
141 { this->base_t::get() = x; return *this; }
142
143 BOOST_INTRUSIVE_FORCEINLINE const key_compare &key_comp() const
144 { return static_cast<const key_compare &>(*this); }
145
146 BOOST_INTRUSIVE_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const
147 { return this->key_comp()(key1, key2); }
148
149 template<class U>
150 BOOST_INTRUSIVE_FORCEINLINE bool operator()( const key_type &key1, const U &nonkey2
151 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
152 { return this->key_comp()(key1, nonkey2); }
153
154 template<class U>
155 BOOST_INTRUSIVE_FORCEINLINE bool operator()(const U &nonkey1, const key_type &key2
156 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
157 { return this->key_comp()(nonkey1, key2); }
158 };
159
160 } //namespace intrusive{
161 } //namespace boost{
162
163 #endif //#ifdef BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP