heap_concepts.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // boost heap: concepts
  2. //
  3. // Copyright (C) 2010 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_CONCEPTS_HPP
  9. #define BOOST_HEAP_CONCEPTS_HPP
  10. #include <boost/concept_check.hpp>
  11. namespace boost {
  12. namespace heap {
  13. template <class C>
  14. struct PriorityQueue:
  15. boost::ForwardContainer<C>
  16. {
  17. typedef typename C::iterator iterator;
  18. typedef typename C::const_iterator const_iterator;
  19. typedef typename C::allocator_type allocator_type;
  20. typedef typename C::value_compare value_compare;
  21. typedef typename C::value_type value_type;
  22. typedef typename C::const_reference const_reference;
  23. BOOST_CONCEPT_USAGE(PriorityQueue)
  24. {
  25. BOOST_CONCEPT_ASSERT((boost::Assignable<value_type>));
  26. BOOST_CONCEPT_ASSERT((boost::Container<C>));
  27. BOOST_CONCEPT_ASSERT((boost::EqualityComparable<C>));
  28. BOOST_CONCEPT_ASSERT((boost::Comparable<C>));
  29. BOOST_CONCEPT_ASSERT((boost::Const_BinaryPredicate<value_compare, value_type, value_type>));
  30. c.swap(c2);
  31. c.clear();
  32. a = c.get_allocator();
  33. typename PriorityQueue::value_type v;
  34. c.push(v);
  35. v = c.top();
  36. c.pop();
  37. cmp = c.value_comp();
  38. // verify tags
  39. has_ordered_iterators = C::has_ordered_iterators;
  40. is_mergable = C::is_mergable;
  41. is_stable = C::is_stable;
  42. }
  43. private:
  44. C c, c2;
  45. allocator_type a;
  46. typename C::value_type v;
  47. value_compare cmp;
  48. bool has_ordered_iterators, is_mergable, is_stable;
  49. };
  50. template <class C>
  51. struct MergablePriorityQueue:
  52. PriorityQueue<C>
  53. {
  54. BOOST_CONCEPT_USAGE(MergablePriorityQueue)
  55. {
  56. C c, c2;
  57. c.merge(c2);
  58. }
  59. };
  60. template <class C>
  61. struct MutablePriorityQueue:
  62. PriorityQueue<C>
  63. {
  64. typedef typename C::handle_type handle_type;
  65. BOOST_CONCEPT_USAGE(MutablePriorityQueue)
  66. {
  67. BOOST_CONCEPT_ASSERT((boost::Assignable<typename MutablePriorityQueue::handle_type>));
  68. typename MutablePriorityQueue::value_type v;
  69. typename MutablePriorityQueue::handle_type h = c.push(v);
  70. typename MutablePriorityQueue::handle_type h2 = c.push(v);
  71. c.update(h, v);
  72. c.increase(h, v);
  73. c.decrease(h, v);
  74. c.update(h);
  75. c.increase(h);
  76. c.decrease(h);
  77. equal = (h == h2);
  78. not_equal = (h != h2);
  79. h2 = h;
  80. }
  81. C c;
  82. bool equal, not_equal;
  83. };
  84. }}
  85. #endif /* BOOST_HEAP_CONCEPTS_HPP */