1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2014-2014
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/libs/intrusive for documentation.
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef BOOST_INTRUSIVE_DETAIL_KEY_NODEPTR_COMP_HPP
14 #define BOOST_INTRUSIVE_DETAIL_KEY_NODEPTR_COMP_HPP
16 #ifndef BOOST_CONFIG_HPP
17 # include <boost/config.hpp>
20 #if defined(BOOST_HAS_PRAGMA_ONCE)
24 #include <boost/intrusive/detail/mpl.hpp>
25 #include <boost/intrusive/detail/ebo_functor_holder.hpp>
26 #include <boost/intrusive/detail/tree_value_compare.hpp>
33 template < class KeyTypeKeyCompare
37 struct key_nodeptr_comp_types
39 typedef ValueTraits value_traits;
40 typedef typename value_traits::value_type value_type;
41 typedef typename value_traits::node_ptr node_ptr;
42 typedef typename value_traits::const_node_ptr const_node_ptr;
43 typedef typename detail::if_c
44 < detail::is_same<KeyOfValue, void>::value
45 , detail::identity<value_type>
48 typedef tree_value_compare
49 <typename ValueTraits::pointer, KeyTypeKeyCompare, key_of_value> base_t;
52 //This function object transforms a key comparison type to
53 //a function that can compare nodes or nodes with nodes or keys.
54 template < class KeyTypeKeyCompare
56 , class KeyOfValue = void
58 struct key_nodeptr_comp
59 //Use public inheritance to avoid MSVC bugs with closures
60 : public key_nodeptr_comp_types<KeyTypeKeyCompare, ValueTraits, KeyOfValue>::base_t
66 typedef key_nodeptr_comp_types<KeyTypeKeyCompare, ValueTraits, KeyOfValue> types_t;
67 typedef typename types_t::value_traits value_traits;
68 typedef typename types_t::value_type value_type;
69 typedef typename types_t::node_ptr node_ptr;
70 typedef typename types_t::const_node_ptr const_node_ptr;
71 typedef typename types_t::base_t base_t;
72 typedef typename types_t::key_of_value key_of_value;
75 struct is_same_or_nodeptr_convertible
77 static const bool same_type = is_same<P1,const_node_ptr>::value || is_same<P1,node_ptr>::value;
78 static const bool value = same_type || is_convertible<P1, const_node_ptr>::value;
82 { return static_cast<const base_t&>(*this); }
84 BOOST_INTRUSIVE_FORCEINLINE key_nodeptr_comp(KeyTypeKeyCompare kcomp, const ValueTraits *traits)
85 : base_t(kcomp), traits_(traits)
90 BOOST_INTRUSIVE_FORCEINLINE bool operator()(const T1 &t1, typename enable_if_c< is_same_or_nodeptr_convertible<T1>::value, sfinae_type* >::type = 0) const
91 { return base().get()(key_of_value()(*traits_->to_value_ptr(t1))); }
95 template<class T1, class T2>
96 BOOST_INTRUSIVE_FORCEINLINE bool operator()
97 (const T1 &t1, const T2 &t2, typename enable_if_c< is_same_or_nodeptr_convertible<T1>::value && is_same_or_nodeptr_convertible<T2>::value, sfinae_type* >::type = 0) const
98 { return base()(*traits_->to_value_ptr(t1), *traits_->to_value_ptr(t2)); }
101 template<class T1, class T2>
102 BOOST_INTRUSIVE_FORCEINLINE bool operator()
103 (const T1 &t1, const T2 &t2, typename enable_if_c< is_same_or_nodeptr_convertible<T1>::value && !is_same_or_nodeptr_convertible<T2>::value, sfinae_type* >::type = 0) const
104 { return base()(*traits_->to_value_ptr(t1), t2); }
107 template<class T1, class T2>
108 BOOST_INTRUSIVE_FORCEINLINE bool operator()
109 (const T1 &t1, const T2 &t2, typename enable_if_c< !is_same_or_nodeptr_convertible<T1>::value && is_same_or_nodeptr_convertible<T2>::value, sfinae_type* >::type = 0) const
110 { return base()(t1, *traits_->to_value_ptr(t2)); }
113 template<class T1, class T2>
114 BOOST_INTRUSIVE_FORCEINLINE bool operator()
115 (const T1 &t1, const T2 &t2, typename enable_if_c< !is_same_or_nodeptr_convertible<T1>::value && !is_same_or_nodeptr_convertible<T2>::value, sfinae_type* >::type = 0) const
116 { return base()(t1, t2); }
118 const ValueTraits *const traits_;
121 } //namespace detail{
122 } //namespace intrusive{
125 #endif //BOOST_INTRUSIVE_DETAIL_KEY_NODEPTR_COMP_HPP