diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:41:18 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:43:11 +0900 |
commit | f763a99a501650eff2c60288aa6f10ef916d769e (patch) | |
tree | 02af7e13f9a38c888ebf340fe764cbe7dae99da9 /boost/intrusive/detail/key_nodeptr_comp.hpp | |
parent | 5cde13f21d36c7224b0e13d11c4b49379ae5210d (diff) | |
download | boost-f763a99a501650eff2c60288aa6f10ef916d769e.tar.gz boost-f763a99a501650eff2c60288aa6f10ef916d769e.tar.bz2 boost-f763a99a501650eff2c60288aa6f10ef916d769e.zip |
Imported Upstream version 1.62.0upstream/1.62.0
Change-Id: I9d4c1ddb7b7d8f0069217ecc582700f9fda6dd4c
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/intrusive/detail/key_nodeptr_comp.hpp')
-rw-r--r-- | boost/intrusive/detail/key_nodeptr_comp.hpp | 110 |
1 files changed, 66 insertions, 44 deletions
diff --git a/boost/intrusive/detail/key_nodeptr_comp.hpp b/boost/intrusive/detail/key_nodeptr_comp.hpp index 1a5ec32acc..9d64f09bcd 100644 --- a/boost/intrusive/detail/key_nodeptr_comp.hpp +++ b/boost/intrusive/detail/key_nodeptr_comp.hpp @@ -23,6 +23,8 @@ #include <boost/intrusive/detail/mpl.hpp> #include <boost/intrusive/detail/ebo_functor_holder.hpp> +#include <boost/intrusive/detail/tree_value_compare.hpp> + namespace boost { namespace intrusive { @@ -30,64 +32,84 @@ namespace detail { template < class KeyTypeKeyCompare , class ValueTraits - , class KeyOfValue = void + , class KeyOfValue > -struct key_nodeptr_comp - //Use public inheritance to avoid MSVC bugs with closures - : public ebo_functor_holder<KeyTypeKeyCompare> +struct key_nodeptr_comp_types { - typedef ValueTraits value_traits; - typedef typename value_traits::value_type value_type; - typedef typename value_traits::node_ptr node_ptr; - typedef typename value_traits::const_node_ptr const_node_ptr; - typedef ebo_functor_holder<KeyTypeKeyCompare> base_t; + typedef ValueTraits value_traits; + typedef typename value_traits::value_type value_type; + typedef typename value_traits::node_ptr node_ptr; + typedef typename value_traits::const_node_ptr const_node_ptr; typedef typename detail::if_c < detail::is_same<KeyOfValue, void>::value , detail::identity<value_type> , KeyOfValue - >::type key_of_value; - typedef typename key_of_value::type key_type; - - key_nodeptr_comp(KeyTypeKeyCompare kcomp, const ValueTraits *traits) - : base_t(kcomp), traits_(traits) - {} + >::type key_of_value; + typedef tree_value_compare + <typename ValueTraits::pointer, KeyTypeKeyCompare, key_of_value> base_t; +}; - template<class T> - struct is_node_ptr +//This function object transforms a key comparison type to +//a function that can compare nodes or nodes with nodes or keys. +template < class KeyTypeKeyCompare + , class ValueTraits + , class KeyOfValue = void + > +struct key_nodeptr_comp + //Use public inheritance to avoid MSVC bugs with closures + : public key_nodeptr_comp_types<KeyTypeKeyCompare, ValueTraits, KeyOfValue>::base_t +{ + typedef key_nodeptr_comp_types<KeyTypeKeyCompare, ValueTraits, KeyOfValue> types_t; + typedef typename types_t::value_traits value_traits; + typedef typename types_t::value_type value_type; + typedef typename types_t::node_ptr node_ptr; + typedef typename types_t::const_node_ptr const_node_ptr; + typedef typename types_t::base_t base_t; + typedef typename types_t::key_of_value key_of_value; + + template <class P1> + struct is_same_or_nodeptr_convertible { - static const bool value = is_same<T, const_node_ptr>::value || is_same<T, node_ptr>::value; + static const bool same_type = is_same<P1,const_node_ptr>::value || is_same<P1,node_ptr>::value; + static const bool value = same_type || is_convertible<P1, const_node_ptr>::value; }; - //key_forward - template<class T> - typename enable_if<is_node_ptr<T>, const key_type &>::type key_forward(const T &node) const - { return key_of_value()(*traits_->to_value_ptr(node)); } + base_t base() const + { return static_cast<const base_t&>(*this); } - template<class T> - #if defined(BOOST_MOVE_HELPERS_RETURN_SFINAE_BROKEN) - const T &key_forward (const T &key, typename disable_if<is_node_ptr<T> >::type* =0) const - #else - typename disable_if<is_node_ptr<T>, const T &>::type key_forward(const T &key) const - #endif - { return key; } - - //operator() 1 arg - template<class KeyType> - bool operator()(const KeyType &key1) const - { return base_t::get()(this->key_forward(key1)); } + BOOST_INTRUSIVE_FORCEINLINE key_nodeptr_comp(KeyTypeKeyCompare kcomp, const ValueTraits *traits) + : base_t(kcomp), traits_(traits) + {} - template<class KeyType> - bool operator()(const KeyType &key1) - { return base_t::get()(this->key_forward(key1)); } + //pred(pnode) + template<class T1> + BOOST_INTRUSIVE_FORCEINLINE bool operator()(const T1 &t1, typename enable_if_c< is_same_or_nodeptr_convertible<T1>::value >::type* =0) const + { return base().get()(key_of_value()(*traits_->to_value_ptr(t1))); } //operator() 2 arg - template<class KeyType, class KeyType2> - bool operator()(const KeyType &key1, const KeyType2 &key2) const - { return base_t::get()(this->key_forward(key1), this->key_forward(key2)); } - - template<class KeyType, class KeyType2> - bool operator()(const KeyType &key1, const KeyType2 &key2) - { return base_t::get()(this->key_forward(key1), this->key_forward(key2)); } + //pred(pnode, pnode) + template<class T1, class T2> + BOOST_INTRUSIVE_FORCEINLINE bool operator() + (const T1 &t1, const T2 &t2, typename enable_if_c< is_same_or_nodeptr_convertible<T1>::value && is_same_or_nodeptr_convertible<T2>::value >::type* =0) const + { return base()(*traits_->to_value_ptr(t1), *traits_->to_value_ptr(t2)); } + + //pred(pnode, key) + template<class T1, class T2> + BOOST_INTRUSIVE_FORCEINLINE bool operator() + (const T1 &t1, const T2 &t2, typename enable_if_c< is_same_or_nodeptr_convertible<T1>::value && !is_same_or_nodeptr_convertible<T2>::value >::type* =0) const + { return base()(*traits_->to_value_ptr(t1), t2); } + + //pred(key, pnode) + template<class T1, class T2> + BOOST_INTRUSIVE_FORCEINLINE bool operator() + (const T1 &t1, const T2 &t2, typename enable_if_c< !is_same_or_nodeptr_convertible<T1>::value && is_same_or_nodeptr_convertible<T2>::value >::type* =0) const + { return base()(t1, *traits_->to_value_ptr(t2)); } + + //pred(key, key) + template<class T1, class T2> + BOOST_INTRUSIVE_FORCEINLINE bool operator() + (const T1 &t1, const T2 &t2, typename enable_if_c< !is_same_or_nodeptr_convertible<T1>::value && !is_same_or_nodeptr_convertible<T2>::value >::type* =0) const + { return base()(t1, t2); } const ValueTraits *const traits_; }; |