tree_value_compare.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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
  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 bool operator()(const key_type &key1, const key_type &key2) const
  70. { return this->key_comp()(key1, key2); }
  71. BOOST_INTRUSIVE_FORCEINLINE bool operator()(const value_type &value1, const value_type &value2) const
  72. { return this->key_comp()(KeyOfValue()(value1), KeyOfValue()(value2)); }
  73. BOOST_INTRUSIVE_FORCEINLINE bool operator()(const key_type &key1, const value_type &value2) const
  74. { return this->key_comp()(key1, KeyOfValue()(value2)); }
  75. BOOST_INTRUSIVE_FORCEINLINE bool operator()(const value_type &value1, const key_type &key2) const
  76. { return this->key_comp()(KeyOfValue()(value1), key2); }
  77. template<class U>
  78. BOOST_INTRUSIVE_FORCEINLINE bool operator()( const key_type &key1, const U &nonkey2
  79. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  80. { return this->key_comp()(key1, nonkey2); }
  81. template<class U>
  82. BOOST_INTRUSIVE_FORCEINLINE bool operator()( const U &nonkey1, const key_type &key2
  83. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  84. { return this->key_comp()(nonkey1, key2); }
  85. template<class U>
  86. BOOST_INTRUSIVE_FORCEINLINE bool operator()( const value_type &value1, const U &nonvalue2
  87. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  88. { return this->key_comp()(KeyOfValue()(value1), nonvalue2); }
  89. template<class U>
  90. BOOST_INTRUSIVE_FORCEINLINE bool operator()( const U &nonvalue1, const value_type &value2
  91. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  92. { return this->key_comp()(nonvalue1, KeyOfValue()(value2)); }
  93. };
  94. template<class ValuePtr, class KeyCompare, class KeyOfValue>
  95. struct tree_value_compare<ValuePtr, KeyCompare, KeyOfValue, true>
  96. : public boost::intrusive::detail::ebo_functor_holder<KeyCompare>
  97. {
  98. typedef typename
  99. boost::movelib::pointer_element<ValuePtr>::type value_type;
  100. typedef KeyCompare key_compare;
  101. typedef KeyOfValue key_of_value;
  102. typedef typename KeyOfValue::type key_type;
  103. typedef boost::intrusive::detail::ebo_functor_holder<KeyCompare> base_t;
  104. BOOST_INTRUSIVE_FORCEINLINE tree_value_compare()
  105. : base_t()
  106. {}
  107. BOOST_INTRUSIVE_FORCEINLINE explicit tree_value_compare(const key_compare &kcomp)
  108. : base_t(kcomp)
  109. {}
  110. BOOST_INTRUSIVE_FORCEINLINE tree_value_compare (const tree_value_compare &x)
  111. : base_t(x.base_t::get())
  112. {}
  113. BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const tree_value_compare &x)
  114. { this->base_t::get() = x.base_t::get(); return *this; }
  115. BOOST_INTRUSIVE_FORCEINLINE tree_value_compare &operator=(const key_compare &x)
  116. { this->base_t::get() = x; return *this; }
  117. BOOST_INTRUSIVE_FORCEINLINE const key_compare &key_comp() const
  118. { return static_cast<const key_compare &>(*this); }
  119. BOOST_INTRUSIVE_FORCEINLINE bool operator()(const key_type &key1, const key_type &key2) const
  120. { return this->key_comp()(key1, key2); }
  121. template<class U>
  122. BOOST_INTRUSIVE_FORCEINLINE bool operator()( const key_type &key1, const U &nonkey2
  123. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  124. { return this->key_comp()(key1, nonkey2); }
  125. template<class U>
  126. BOOST_INTRUSIVE_FORCEINLINE bool operator()(const U &nonkey1, const key_type &key2
  127. , typename disable_if_smartref_to<U, ValuePtr>::type* = 0) const
  128. { return this->key_comp()(nonkey1, key2); }
  129. };
  130. } //namespace intrusive{
  131. } //namespace boost{
  132. #endif //#ifdef BOOST_INTRUSIVE_DETAIL_TREE_VALUE_COMPARE_HPP