policies.hpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // boost heap
  2. //
  3. // Copyright (C) 2010-2011 Tim Blechmann
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_HEAP_POLICIES_HPP
  9. #define BOOST_HEAP_POLICIES_HPP
  10. #include <boost/concept_check.hpp>
  11. #include <boost/parameter/aux_/void.hpp>
  12. #include <boost/parameter/binding.hpp>
  13. #include <boost/parameter/name.hpp>
  14. #include <boost/parameter/parameters.hpp>
  15. #include <boost/parameter/template_keyword.hpp>
  16. #include <type_traits>
  17. #ifdef BOOST_HAS_PRAGMA_ONCE
  18. # pragma once
  19. #endif
  20. namespace boost { namespace heap {
  21. #ifndef BOOST_DOXYGEN_INVOKED
  22. BOOST_PARAMETER_TEMPLATE_KEYWORD( allocator )
  23. BOOST_PARAMETER_TEMPLATE_KEYWORD( compare )
  24. namespace tag {
  25. struct stable;
  26. } // namespace tag
  27. template < bool T >
  28. struct stable : boost::parameter::template_keyword< tag::stable, std::integral_constant< bool, T > >
  29. {};
  30. namespace tag {
  31. struct mutable_;
  32. } // namespace tag
  33. template < bool T >
  34. struct mutable_ : boost::parameter::template_keyword< tag::mutable_, std::integral_constant< bool, T > >
  35. {};
  36. namespace tag {
  37. struct constant_time_size;
  38. } // namespace tag
  39. template < bool T >
  40. struct constant_time_size :
  41. boost::parameter::template_keyword< tag::constant_time_size, std::integral_constant< bool, T > >
  42. {};
  43. namespace tag {
  44. struct store_parent_pointer;
  45. } // namespace tag
  46. template < bool T >
  47. struct store_parent_pointer :
  48. boost::parameter::template_keyword< tag::store_parent_pointer, std::integral_constant< bool, T > >
  49. {};
  50. namespace tag {
  51. struct arity;
  52. } // namespace tag
  53. template < unsigned int T >
  54. struct arity : boost::parameter::template_keyword< tag::arity, std::integral_constant< int, T > >
  55. {};
  56. namespace tag {
  57. struct objects_per_page;
  58. } // namespace tag
  59. template < unsigned int T >
  60. struct objects_per_page : boost::parameter::template_keyword< tag::objects_per_page, std::integral_constant< int, T > >
  61. {};
  62. BOOST_PARAMETER_TEMPLATE_KEYWORD( stability_counter_type )
  63. namespace detail {
  64. template < typename bound_args, typename tag_type >
  65. struct has_arg
  66. {
  67. typedef typename boost::parameter::binding< bound_args, tag_type, void >::type type;
  68. static const bool value = !std::is_void< type >::value;
  69. };
  70. template < typename bound_args >
  71. struct extract_stable
  72. {
  73. static const bool has_stable = has_arg< bound_args, tag::stable >::value;
  74. typedef
  75. typename std::conditional< has_stable, typename has_arg< bound_args, tag::stable >::type, std::false_type >::type
  76. stable_t;
  77. static const bool value = stable_t::value;
  78. };
  79. template < typename bound_args >
  80. struct extract_mutable
  81. {
  82. static const bool has_mutable = has_arg< bound_args, tag::mutable_ >::value;
  83. typedef
  84. typename std::conditional< has_mutable, typename has_arg< bound_args, tag::mutable_ >::type, std::false_type >::type
  85. mutable_t;
  86. static const bool value = mutable_t::value;
  87. };
  88. } // namespace detail
  89. #else
  90. /** \brief Specifies the predicate for the heap order
  91. */
  92. template < typename T >
  93. struct compare
  94. {};
  95. /** \brief Configure heap as mutable
  96. *
  97. * Certain heaps need to be configured specifically do be mutable.
  98. *
  99. * */
  100. template < bool T >
  101. struct mutable_
  102. {};
  103. /** \brief Specifies allocator for the internal memory management
  104. */
  105. template < typename T >
  106. struct allocator
  107. {};
  108. /** \brief Configure a heap as \b stable
  109. *
  110. * A priority queue is stable, if elements with the same priority are popped from the heap, in the same order as
  111. * they are inserted.
  112. * */
  113. template < bool T >
  114. struct stable
  115. {};
  116. /** \brief Specifies the type for stability counter
  117. *
  118. * */
  119. template < typename IntType >
  120. struct stability_counter_type
  121. {};
  122. /** \brief Configures complexity of <tt> size() </tt>
  123. *
  124. * Specifies, whether size() should have linear or constant complexity.
  125. * */
  126. template < bool T >
  127. struct constant_time_size
  128. {};
  129. /** \brief Store parent pointer in heap node.
  130. *
  131. * Maintaining a parent pointer adds some maintenance and size overhead, but iterating a heap is more efficient.
  132. * */
  133. template < bool T >
  134. struct store_parent_pointer
  135. {};
  136. /** \brief Specify arity.
  137. *
  138. * Specifies the arity of a D-ary heap
  139. * */
  140. template < unsigned int T >
  141. struct arity
  142. {};
  143. #endif
  144. }} // namespace boost::heap
  145. #endif /* BOOST_HEAP_POLICIES_HPP */