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
62 typedef key_nodeptr_comp_types<KeyTypeKeyCompare, ValueTraits, KeyOfValue> types_t;
63 typedef typename types_t::value_traits value_traits;
64 typedef typename types_t::value_type value_type;
65 typedef typename types_t::node_ptr node_ptr;
66 typedef typename types_t::const_node_ptr const_node_ptr;
67 typedef typename types_t::base_t base_t;
68 typedef typename types_t::key_of_value key_of_value;
71 struct is_same_or_nodeptr_convertible
73 static const bool same_type = is_same<P1,const_node_ptr>::value || is_same<P1,node_ptr>::value;
74 static const bool value = same_type || is_convertible<P1, const_node_ptr>::value;
78 { return static_cast<const base_t&>(*this); }
80 BOOST_INTRUSIVE_FORCEINLINE key_nodeptr_comp(KeyTypeKeyCompare kcomp, const ValueTraits *traits)
81 : base_t(kcomp), traits_(traits)
86 BOOST_INTRUSIVE_FORCEINLINE bool operator()(const T1 &t1, typename enable_if_c< is_same_or_nodeptr_convertible<T1>::value >::type* =0) const
87 { return base().get()(key_of_value()(*traits_->to_value_ptr(t1))); }
91 template<class T1, class T2>
92 BOOST_INTRUSIVE_FORCEINLINE bool operator()
93 (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
94 { return base()(*traits_->to_value_ptr(t1), *traits_->to_value_ptr(t2)); }
97 template<class T1, class T2>
98 BOOST_INTRUSIVE_FORCEINLINE bool operator()
99 (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
100 { return base()(*traits_->to_value_ptr(t1), t2); }
103 template<class T1, class T2>
104 BOOST_INTRUSIVE_FORCEINLINE bool operator()
105 (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
106 { return base()(t1, *traits_->to_value_ptr(t2)); }
109 template<class T1, class T2>
110 BOOST_INTRUSIVE_FORCEINLINE bool operator()
111 (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
112 { return base()(t1, t2); }
114 const ValueTraits *const traits_;
117 } //namespace detail{
118 } //namespace intrusive{
121 #endif //BOOST_INTRUSIVE_DETAIL_KEY_NODEPTR_COMP_HPP