1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
10 #ifndef BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP
11 #define BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP
13 #ifndef BOOST_CONFIG_HPP
14 # include <boost/config.hpp>
17 #if defined(BOOST_HAS_PRAGMA_ONCE)
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>
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
34 <From, typename pointer_traits
38 <From, typename pointer_traits
39 < typename pointer_rebind
40 <ValuePtr, const typename pointer_element<ValuePtr>::type>::type>
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>
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;
57 typedef boost::intrusive::detail::ebo_functor_holder<KeyCompare> base_t;
59 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare()
63 BOOST_INTRUSIVE_FORCEINLINE explicit tree_value_compare(const key_compare &kcomp)
67 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare (const tree_value_compare &x)
68 : base_t(x.base_t::get())
71 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const tree_value_compare &x)
72 { this->base_t::get() = x.base_t::get(); return *this; }
74 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const key_compare &x)
75 { this->base_t::get() = x; return *this; }
77 BOOST_INTRUSIVE_FORCEINLINE const key_compare &key_comp() const
78 { return static_cast<const key_compare &>(*this); }
80 BOOST_INTRUSIVE_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const
81 { return this->key_comp()(key1, key2); }
83 BOOST_INTRUSIVE_FORCEINLINE bool operator()(const value_type &value1, const value_type &value2) const
84 { return this->key_comp()(KeyOfValue()(value1), KeyOfValue()(value2)); }
86 BOOST_INTRUSIVE_FORCEINLINE bool operator()(const key_type &key1, const value_type &value2) const
87 { return this->key_comp()(key1, KeyOfValue()(value2)); }
89 BOOST_INTRUSIVE_FORCEINLINE bool operator()(const value_type &value1, const key_type &key2) const
90 { return this->key_comp()(KeyOfValue()(value1), key2); }
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); }
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); }
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); }
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)); }
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>
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;
122 typedef boost::intrusive::detail::ebo_functor_holder<KeyCompare> base_t;
125 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare()
129 BOOST_INTRUSIVE_FORCEINLINE explicit tree_value_compare(const key_compare &kcomp)
133 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare (const tree_value_compare &x)
134 : base_t(x.base_t::get())
137 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const tree_value_compare &x)
138 { this->base_t::get() = x.base_t::get(); return *this; }
140 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const key_compare &x)
141 { this->base_t::get() = x; return *this; }
143 BOOST_INTRUSIVE_FORCEINLINE const key_compare &key_comp() const
144 { return static_cast<const key_compare &>(*this); }
146 BOOST_INTRUSIVE_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const
147 { return this->key_comp()(key1, key2); }
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); }
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); }
160 } //namespace intrusive{
163 #endif //#ifdef BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP