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 41 , const typename boost::movelib::pointer_element<ValuePtr>::type>::type> 42 ::reference>::value 43 > 44 {}; 45 46 //This function object takes a KeyCompare function object 47 //and compares values that contains keys using KeyOfValue 48 template< class ValuePtr, class KeyCompare, class KeyOfValue, class Ret = bool 49 , bool = boost::intrusive::detail::is_same 50 <typename boost::movelib::pointer_element<ValuePtr>::type, typename KeyOfValue::type>::value > 51 struct tree_value_compare 52 : public boost::intrusive::detail::ebo_functor_holder<KeyCompare> 53 { 54 typedef typename 55 boost::movelib::pointer_element<ValuePtr>::type value_type; 56 typedef KeyCompare key_compare; 57 typedef KeyOfValue key_of_value; 58 typedef typename KeyOfValue::type key_type; 59 60 typedef boost::intrusive::detail::ebo_functor_holder<KeyCompare> base_t; 61 tree_value_compareboost::intrusive::tree_value_compare62 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare() 63 : base_t() 64 {} 65 tree_value_compareboost::intrusive::tree_value_compare66 BOOST_INTRUSIVE_FORCEINLINE explicit tree_value_compare(const key_compare &kcomp) 67 : base_t(kcomp) 68 {} 69 tree_value_compareboost::intrusive::tree_value_compare70 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare (const tree_value_compare &x) 71 : base_t(x.base_t::get()) 72 {} 73 operator =boost::intrusive::tree_value_compare74 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const tree_value_compare &x) 75 { this->base_t::get() = x.base_t::get(); return *this; } 76 operator =boost::intrusive::tree_value_compare77 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const key_compare &x) 78 { this->base_t::get() = x; return *this; } 79 key_compboost::intrusive::tree_value_compare80 BOOST_INTRUSIVE_FORCEINLINE const key_compare &key_comp() const 81 { return static_cast<const key_compare &>(*this); } 82 operator ()boost::intrusive::tree_value_compare83 BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key) const 84 { return this->key_comp()(key); } 85 operator ()boost::intrusive::tree_value_compare86 BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const value_type &value) const 87 { return this->key_comp()(KeyOfValue()(value)); } 88 89 template<class U> operator ()boost::intrusive::tree_value_compare90 BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const U &nonkey 91 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const 92 { return this->key_comp()(nonkey); } 93 operator ()boost::intrusive::tree_value_compare94 BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key1, const key_type &key2) const 95 { return this->key_comp()(key1, key2); } 96 operator ()boost::intrusive::tree_value_compare97 BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const value_type &value1, const value_type &value2) const 98 { return this->key_comp()(KeyOfValue()(value1), KeyOfValue()(value2)); } 99 operator ()boost::intrusive::tree_value_compare100 BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key1, const value_type &value2) const 101 { return this->key_comp()(key1, KeyOfValue()(value2)); } 102 operator ()boost::intrusive::tree_value_compare103 BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const value_type &value1, const key_type &key2) const 104 { return this->key_comp()(KeyOfValue()(value1), key2); } 105 106 template<class U> operator ()boost::intrusive::tree_value_compare107 BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const key_type &key1, const U &nonkey2 108 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const 109 { return this->key_comp()(key1, nonkey2); } 110 111 template<class U> operator ()boost::intrusive::tree_value_compare112 BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const U &nonkey1, const key_type &key2 113 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const 114 { return this->key_comp()(nonkey1, key2); } 115 116 template<class U> operator ()boost::intrusive::tree_value_compare117 BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const value_type &value1, const U &nonvalue2 118 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const 119 { return this->key_comp()(KeyOfValue()(value1), nonvalue2); } 120 121 template<class U> operator ()boost::intrusive::tree_value_compare122 BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const U &nonvalue1, const value_type &value2 123 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const 124 { return this->key_comp()(nonvalue1, KeyOfValue()(value2)); } 125 }; 126 127 template<class ValuePtr, class KeyCompare, class KeyOfValue, class Ret> 128 struct tree_value_compare<ValuePtr, KeyCompare, KeyOfValue, Ret, true> 129 : public boost::intrusive::detail::ebo_functor_holder<KeyCompare> 130 { 131 typedef typename 132 boost::movelib::pointer_element<ValuePtr>::type value_type; 133 typedef KeyCompare key_compare; 134 typedef KeyOfValue key_of_value; 135 typedef typename KeyOfValue::type key_type; 136 137 typedef boost::intrusive::detail::ebo_functor_holder<KeyCompare> base_t; 138 139 tree_value_compareboost::intrusive::tree_value_compare140 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare() 141 : base_t() 142 {} 143 tree_value_compareboost::intrusive::tree_value_compare144 BOOST_INTRUSIVE_FORCEINLINE explicit tree_value_compare(const key_compare &kcomp) 145 : base_t(kcomp) 146 {} 147 tree_value_compareboost::intrusive::tree_value_compare148 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare (const tree_value_compare &x) 149 : base_t(x.base_t::get()) 150 {} 151 operator =boost::intrusive::tree_value_compare152 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const tree_value_compare &x) 153 { this->base_t::get() = x.base_t::get(); return *this; } 154 operator =boost::intrusive::tree_value_compare155 BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const key_compare &x) 156 { this->base_t::get() = x; return *this; } 157 key_compboost::intrusive::tree_value_compare158 BOOST_INTRUSIVE_FORCEINLINE const key_compare &key_comp() const 159 { return static_cast<const key_compare &>(*this); } 160 operator ()boost::intrusive::tree_value_compare161 BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key) const 162 { return this->key_comp()(key); } 163 164 template<class U> operator ()boost::intrusive::tree_value_compare165 BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const U &nonkey 166 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const 167 { return this->key_comp()(nonkey); } 168 operator ()boost::intrusive::tree_value_compare169 BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key1, const key_type &key2) const 170 { return this->key_comp()(key1, key2); } 171 172 template<class U> operator ()boost::intrusive::tree_value_compare173 BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const key_type &key1, const U &nonkey2 174 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const 175 { return this->key_comp()(key1, nonkey2); } 176 177 template<class U> operator ()boost::intrusive::tree_value_compare178 BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const U &nonkey1, const key_type &key2 179 , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const 180 { return this->key_comp()(nonkey1, key2); } 181 }; 182 183 } //namespace intrusive{ 184 } //namespace boost{ 185 186 #endif //#ifdef BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP 187