tree_value_compare.hpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP
  11. #define BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #if defined(BOOST_HAS_PRAGMA_ONCE)
  16. # pragma once
  17. #endif
  18. #include <boost/intrusive/detail/workaround.hpp>
  19. #include <boost/intrusive/detail/mpl.hpp>
  20. #include <boost/intrusive/detail/ebo_functor_holder.hpp>
  21. #include <boost/intrusive/pointer_traits.hpp>
  22. namespace boost{
  23. namespace intrusive{
  24. //Needed to support smart references to value types
  25. template <class From, class ValuePtr>
  26. struct disable_if_smartref_to
  27. : detail::disable_if_c
  28. < detail::is_same
  29. <From, typename pointer_traits
  30. <ValuePtr>
  31. ::reference>::value
  32. || detail::is_same
  33. <From, typename pointer_traits
  34. < typename pointer_rebind
  35. < ValuePtr
  36. , const typename boost::movelib::pointer_element<ValuePtr>::type>::type>
  37. ::reference>::value
  38. >
  39. {};
  40. //This function object takes a KeyCompare function object
  41. //and compares values that contains keys using KeyOfValue
  42. template< class ValuePtr, class KeyCompare, class KeyOfValue, class Ret = bool
  43. , bool = boost::intrusive::detail::is_same
  44. <typename boost::movelib::pointer_element<ValuePtr>::type, typename KeyOfValue::type>::value >
  45. struct tree_value_compare
  46. : public boost::intrusive::detail::ebo_functor_holder<KeyCompare>
  47. {
  48. typedef typename
  49. boost::movelib::pointer_element<ValuePtr>::type value_type;
  50. typedef KeyCompare key_compare;
  51. typedef KeyOfValue key_of_value;
  52. typedef typename KeyOfValue::type key_type;
  53. typedef boost::intrusive::detail::ebo_functor_holder<KeyCompare> base_t;
  54. BOOST_INTRUSIVE_FORCEINLINE tree_value_compare()
  55. : base_t()
  56. {}
  57. BOOST_INTRUSIVE_FORCEINLINE explicit tree_value_compare(const key_compare &kcomp)
  58. : base_t(kcomp)
  59. {}
  60. BOOST_INTRUSIVE_FORCEINLINE tree_value_compare (const tree_value_compare &x)
  61. : base_t(x.base_t::get())
  62. {}
  63. BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const tree_value_compare &x)
  64. { this->base_t::get() = x.base_t::get(); return *this; }
  65. BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const key_compare &x)
  66. { this->base_t::get() = x; return *this; }
  67. BOOST_INTRUSIVE_FORCEINLINE const key_compare &key_comp() const
  68. { return static_cast<const key_compare &>(*this); }
  69. BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key) const
  70. { return this->key_comp()(key); }
  71. BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const value_type &value) const
  72. { return this->key_comp()(KeyOfValue()(value)); }
  73. template<class U>
  74. BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const U &nonkey
  75. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  76. { return this->key_comp()(nonkey); }
  77. BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key1, const key_type &key2) const
  78. { return this->key_comp()(key1, key2); }
  79. BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const value_type &value1, const value_type &value2) const
  80. { return this->key_comp()(KeyOfValue()(value1), KeyOfValue()(value2)); }
  81. BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key1, const value_type &value2) const
  82. { return this->key_comp()(key1, KeyOfValue()(value2)); }
  83. BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const value_type &value1, const key_type &key2) const
  84. { return this->key_comp()(KeyOfValue()(value1), key2); }
  85. template<class U>
  86. BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const key_type &key1, const U &nonkey2
  87. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  88. { return this->key_comp()(key1, nonkey2); }
  89. template<class U>
  90. BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const U &nonkey1, const key_type &key2
  91. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  92. { return this->key_comp()(nonkey1, key2); }
  93. template<class U>
  94. BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const value_type &value1, const U &nonvalue2
  95. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  96. { return this->key_comp()(KeyOfValue()(value1), nonvalue2); }
  97. template<class U>
  98. BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const U &nonvalue1, const value_type &value2
  99. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  100. { return this->key_comp()(nonvalue1, KeyOfValue()(value2)); }
  101. };
  102. template<class ValuePtr, class KeyCompare, class KeyOfValue, class Ret>
  103. struct tree_value_compare<ValuePtr, KeyCompare, KeyOfValue, Ret, true>
  104. : public boost::intrusive::detail::ebo_functor_holder<KeyCompare>
  105. {
  106. typedef typename
  107. boost::movelib::pointer_element<ValuePtr>::type value_type;
  108. typedef KeyCompare key_compare;
  109. typedef KeyOfValue key_of_value;
  110. typedef typename KeyOfValue::type key_type;
  111. typedef boost::intrusive::detail::ebo_functor_holder<KeyCompare> base_t;
  112. BOOST_INTRUSIVE_FORCEINLINE tree_value_compare()
  113. : base_t()
  114. {}
  115. BOOST_INTRUSIVE_FORCEINLINE explicit tree_value_compare(const key_compare &kcomp)
  116. : base_t(kcomp)
  117. {}
  118. BOOST_INTRUSIVE_FORCEINLINE tree_value_compare (const tree_value_compare &x)
  119. : base_t(x.base_t::get())
  120. {}
  121. BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const tree_value_compare &x)
  122. { this->base_t::get() = x.base_t::get(); return *this; }
  123. BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const key_compare &x)
  124. { this->base_t::get() = x; return *this; }
  125. BOOST_INTRUSIVE_FORCEINLINE const key_compare &key_comp() const
  126. { return static_cast<const key_compare &>(*this); }
  127. BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key) const
  128. { return this->key_comp()(key); }
  129. template<class U>
  130. BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const U &nonkey
  131. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  132. { return this->key_comp()(nonkey); }
  133. BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const key_type &key1, const key_type &key2) const
  134. { return this->key_comp()(key1, key2); }
  135. template<class U>
  136. BOOST_INTRUSIVE_FORCEINLINE Ret operator()( const key_type &key1, const U &nonkey2
  137. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  138. { return this->key_comp()(key1, nonkey2); }
  139. template<class U>
  140. BOOST_INTRUSIVE_FORCEINLINE Ret operator()(const U &nonkey1, const key_type &key2
  141. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  142. { return this->key_comp()(nonkey1, key2); }
  143. };
  144. } //namespace intrusive{
  145. } //namespace boost{
  146. #endif //#ifdef BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP