heap_concepts.hpp 2.7 KB

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