Chris@102
|
1 /////////////////////////////////////////////////////////////////////////////
|
Chris@102
|
2 //
|
Chris@102
|
3 // (C) Copyright Ion Gaztanaga 2014-2014
|
Chris@102
|
4 //
|
Chris@102
|
5 // Distributed under the Boost Software License, Version 1.0.
|
Chris@102
|
6 // (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@102
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
8 //
|
Chris@102
|
9 // See http://www.boost.org/libs/intrusive for documentation.
|
Chris@102
|
10 //
|
Chris@102
|
11 /////////////////////////////////////////////////////////////////////////////
|
Chris@102
|
12
|
Chris@102
|
13 #ifndef BOOST_INTRUSIVE_DETAIL_KEY_NODEPTR_COMP_HPP
|
Chris@102
|
14 #define BOOST_INTRUSIVE_DETAIL_KEY_NODEPTR_COMP_HPP
|
Chris@102
|
15
|
Chris@102
|
16 #ifndef BOOST_CONFIG_HPP
|
Chris@102
|
17 # include <boost/config.hpp>
|
Chris@102
|
18 #endif
|
Chris@102
|
19
|
Chris@102
|
20 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@102
|
21 # pragma once
|
Chris@102
|
22 #endif
|
Chris@102
|
23
|
Chris@102
|
24 #include <boost/intrusive/detail/mpl.hpp>
|
Chris@102
|
25 #include <boost/intrusive/detail/ebo_functor_holder.hpp>
|
Chris@102
|
26
|
Chris@102
|
27 namespace boost {
|
Chris@102
|
28 namespace intrusive {
|
Chris@102
|
29 namespace detail {
|
Chris@102
|
30
|
Chris@102
|
31 template<class KeyValueCompare, class ValueTraits>
|
Chris@102
|
32 struct key_nodeptr_comp
|
Chris@102
|
33 //Use public inheritance to avoid MSVC bugs with closures
|
Chris@102
|
34 : public ebo_functor_holder<KeyValueCompare>
|
Chris@102
|
35 {
|
Chris@102
|
36 typedef ValueTraits value_traits;
|
Chris@102
|
37 typedef typename value_traits::value_type value_type;
|
Chris@102
|
38 typedef typename value_traits::node_ptr node_ptr;
|
Chris@102
|
39 typedef typename value_traits::const_node_ptr const_node_ptr;
|
Chris@102
|
40 typedef ebo_functor_holder<KeyValueCompare> base_t;
|
Chris@102
|
41
|
Chris@102
|
42 key_nodeptr_comp(KeyValueCompare kcomp, const ValueTraits *traits)
|
Chris@102
|
43 : base_t(kcomp), traits_(traits)
|
Chris@102
|
44 {}
|
Chris@102
|
45
|
Chris@102
|
46 template<class T>
|
Chris@102
|
47 struct is_node_ptr
|
Chris@102
|
48 {
|
Chris@102
|
49 static const bool value = is_same<T, const_node_ptr>::value || is_same<T, node_ptr>::value;
|
Chris@102
|
50 };
|
Chris@102
|
51
|
Chris@102
|
52 //key_forward
|
Chris@102
|
53 template<class T>
|
Chris@102
|
54 const value_type & key_forward
|
Chris@102
|
55 (const T &node, typename enable_if_c<is_node_ptr<T>::value>::type * = 0) const
|
Chris@102
|
56 { return *traits_->to_value_ptr(node); }
|
Chris@102
|
57
|
Chris@102
|
58 template<class T>
|
Chris@102
|
59 const T & key_forward(const T &key, typename enable_if_c<!is_node_ptr<T>::value>::type* = 0) const
|
Chris@102
|
60 { return key; }
|
Chris@102
|
61
|
Chris@102
|
62 //operator() 1 arg
|
Chris@102
|
63 template<class KeyType>
|
Chris@102
|
64 bool operator()(const KeyType &key1) const
|
Chris@102
|
65 { return base_t::get()(this->key_forward(key1)); }
|
Chris@102
|
66
|
Chris@102
|
67 template<class KeyType>
|
Chris@102
|
68 bool operator()(const KeyType &key1)
|
Chris@102
|
69 { return base_t::get()(this->key_forward(key1)); }
|
Chris@102
|
70
|
Chris@102
|
71 //operator() 2 arg
|
Chris@102
|
72 template<class KeyType, class KeyType2>
|
Chris@102
|
73 bool operator()(const KeyType &key1, const KeyType2 &key2) const
|
Chris@102
|
74 { return base_t::get()(this->key_forward(key1), this->key_forward(key2)); }
|
Chris@102
|
75
|
Chris@102
|
76 template<class KeyType, class KeyType2>
|
Chris@102
|
77 bool operator()(const KeyType &key1, const KeyType2 &key2)
|
Chris@102
|
78 { return base_t::get()(this->key_forward(key1), this->key_forward(key2)); }
|
Chris@102
|
79
|
Chris@102
|
80 const ValueTraits *const traits_;
|
Chris@102
|
81 };
|
Chris@102
|
82
|
Chris@102
|
83 } //namespace detail{
|
Chris@102
|
84 } //namespace intrusive{
|
Chris@102
|
85 } //namespace boost{
|
Chris@102
|
86
|
Chris@102
|
87 #endif //BOOST_INTRUSIVE_DETAIL_KEY_NODEPTR_COMP_HPP
|