policies.hpp 4.3 KB

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