////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/container for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP #define BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP #ifndef BOOST_CONFIG_HPP # include #endif #if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif #include #include #include #include namespace boost{ namespace intrusive{ //Needed to support smart references to value types template struct disable_if_smartref_to : detail::disable_if_c < detail::is_same ::reference>::value || detail::is_same ::type>::type> ::reference>::value > {}; //This function object takes a KeyCompare function object //and compares values that contains keys using KeyOfValue template< class ValuePtr, class KeyCompare, class KeyOfValue , bool = boost::intrusive::detail::is_same::type, typename KeyOfValue::type>::value > struct tree_value_compare : public boost::intrusive::detail::ebo_functor_holder { typedef typename pointer_element::type value_type; typedef KeyCompare key_compare; typedef KeyOfValue key_of_value; typedef typename KeyOfValue::type key_type; typedef boost::intrusive::detail::ebo_functor_holder base_t; BOOST_INTRUSIVE_FORCEINLINE tree_value_compare() : base_t() {} BOOST_INTRUSIVE_FORCEINLINE explicit tree_value_compare(const key_compare &kcomp) : base_t(kcomp) {} BOOST_INTRUSIVE_FORCEINLINE tree_value_compare (const tree_value_compare &x) : base_t(x.base_t::get()) {} BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const tree_value_compare &x) { this->base_t::get() = x.base_t::get(); return *this; } BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const key_compare &x) { this->base_t::get() = x; return *this; } BOOST_INTRUSIVE_FORCEINLINE const key_compare &key_comp() const { return static_cast(*this); } BOOST_INTRUSIVE_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const { return this->key_comp()(key1, key2); } BOOST_INTRUSIVE_FORCEINLINE bool operator()(const value_type &value1, const value_type &value2) const { return this->key_comp()(KeyOfValue()(value1), KeyOfValue()(value2)); } BOOST_INTRUSIVE_FORCEINLINE bool operator()(const key_type &key1, const value_type &value2) const { return this->key_comp()(key1, KeyOfValue()(value2)); } BOOST_INTRUSIVE_FORCEINLINE bool operator()(const value_type &value1, const key_type &key2) const { return this->key_comp()(KeyOfValue()(value1), key2); } template BOOST_INTRUSIVE_FORCEINLINE bool operator()( const key_type &key1, const U &nonkey2 , typename disable_if_smartref_to::type* = 0) const { return this->key_comp()(key1, nonkey2); } template BOOST_INTRUSIVE_FORCEINLINE bool operator()( const U &nonkey1, const key_type &key2 , typename disable_if_smartref_to::type* = 0) const { return this->key_comp()(nonkey1, key2); } template BOOST_INTRUSIVE_FORCEINLINE bool operator()( const value_type &value1, const U &nonvalue2 , typename disable_if_smartref_to::type* = 0) const { return this->key_comp()(KeyOfValue()(value1), nonvalue2); } template BOOST_INTRUSIVE_FORCEINLINE bool operator()( const U &nonvalue1, const value_type &value2 , typename disable_if_smartref_to::type* = 0) const { return this->key_comp()(nonvalue1, KeyOfValue()(value2)); } }; template struct tree_value_compare : public boost::intrusive::detail::ebo_functor_holder { typedef typename pointer_element::type value_type; typedef KeyCompare key_compare; typedef KeyOfValue key_of_value; typedef typename KeyOfValue::type key_type; typedef boost::intrusive::detail::ebo_functor_holder base_t; BOOST_INTRUSIVE_FORCEINLINE tree_value_compare() : base_t() {} BOOST_INTRUSIVE_FORCEINLINE explicit tree_value_compare(const key_compare &kcomp) : base_t(kcomp) {} BOOST_INTRUSIVE_FORCEINLINE tree_value_compare (const tree_value_compare &x) : base_t(x.base_t::get()) {} BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const tree_value_compare &x) { this->base_t::get() = x.base_t::get(); return *this; } BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const key_compare &x) { this->base_t::get() = x; return *this; } BOOST_INTRUSIVE_FORCEINLINE const key_compare &key_comp() const { return static_cast(*this); } BOOST_INTRUSIVE_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const { return this->key_comp()(key1, key2); } template BOOST_INTRUSIVE_FORCEINLINE bool operator()( const key_type &key1, const U &nonkey2 , typename disable_if_smartref_to::type* = 0) const { return this->key_comp()(key1, nonkey2); } template BOOST_INTRUSIVE_FORCEINLINE bool operator()(const U &nonkey1, const key_type &key2 , typename disable_if_smartref_to::type* = 0) const { return this->key_comp()(nonkey1, key2); } }; } //namespace intrusive{ } //namespace boost{ #endif //#ifdef BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP