Chris@16
|
1 // boost heap: concepts
|
Chris@16
|
2 //
|
Chris@16
|
3 // Copyright (C) 2010 Tim Blechmann
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
6 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8
|
Chris@16
|
9 #ifndef BOOST_HEAP_CONCEPTS_HPP
|
Chris@16
|
10 #define BOOST_HEAP_CONCEPTS_HPP
|
Chris@16
|
11
|
Chris@16
|
12 #include <boost/concept_check.hpp>
|
Chris@16
|
13
|
Chris@16
|
14 namespace boost {
|
Chris@16
|
15 namespace heap {
|
Chris@16
|
16
|
Chris@16
|
17
|
Chris@16
|
18 template <class C>
|
Chris@16
|
19 struct PriorityQueue:
|
Chris@16
|
20 boost::ForwardContainer<C>
|
Chris@16
|
21 {
|
Chris@16
|
22 typedef typename C::iterator iterator;
|
Chris@16
|
23 typedef typename C::const_iterator const_iterator;
|
Chris@16
|
24 typedef typename C::allocator_type allocator_type;
|
Chris@16
|
25 typedef typename C::value_compare value_compare;
|
Chris@16
|
26 typedef typename C::value_type value_type;
|
Chris@16
|
27 typedef typename C::const_reference const_reference;
|
Chris@16
|
28
|
Chris@16
|
29
|
Chris@16
|
30 BOOST_CONCEPT_USAGE(PriorityQueue)
|
Chris@16
|
31 {
|
Chris@16
|
32 BOOST_CONCEPT_ASSERT((boost::Assignable<value_type>));
|
Chris@16
|
33 BOOST_CONCEPT_ASSERT((boost::Container<C>));
|
Chris@16
|
34 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<C>));
|
Chris@16
|
35 BOOST_CONCEPT_ASSERT((boost::Comparable<C>));
|
Chris@16
|
36
|
Chris@16
|
37 BOOST_CONCEPT_ASSERT((boost::Const_BinaryPredicate<value_compare, value_type, value_type>));
|
Chris@16
|
38
|
Chris@16
|
39 c.swap(c2);
|
Chris@16
|
40 c.clear();
|
Chris@16
|
41 a = c.get_allocator();
|
Chris@16
|
42
|
Chris@16
|
43 typename PriorityQueue::value_type v;
|
Chris@16
|
44 c.push(v);
|
Chris@16
|
45
|
Chris@16
|
46 v = c.top();
|
Chris@16
|
47 c.pop();
|
Chris@16
|
48
|
Chris@16
|
49 cmp = c.value_comp();
|
Chris@16
|
50
|
Chris@16
|
51 // verify tags
|
Chris@16
|
52 has_ordered_iterators = C::has_ordered_iterators;
|
Chris@16
|
53 is_mergable = C::is_mergable;
|
Chris@16
|
54 is_stable = C::is_stable;
|
Chris@16
|
55 }
|
Chris@16
|
56
|
Chris@16
|
57 private:
|
Chris@16
|
58 C c, c2;
|
Chris@16
|
59 allocator_type a;
|
Chris@16
|
60 typename C::value_type v;
|
Chris@16
|
61 value_compare cmp;
|
Chris@16
|
62 bool has_ordered_iterators, is_mergable, is_stable;
|
Chris@16
|
63 };
|
Chris@16
|
64
|
Chris@16
|
65 template <class C>
|
Chris@16
|
66 struct MergablePriorityQueue:
|
Chris@16
|
67 PriorityQueue<C>
|
Chris@16
|
68 {
|
Chris@16
|
69 BOOST_CONCEPT_USAGE(MergablePriorityQueue)
|
Chris@16
|
70 {
|
Chris@16
|
71 C c, c2;
|
Chris@16
|
72 c.merge(c2);
|
Chris@16
|
73 }
|
Chris@16
|
74 };
|
Chris@16
|
75
|
Chris@16
|
76
|
Chris@16
|
77 template <class C>
|
Chris@16
|
78 struct MutablePriorityQueue:
|
Chris@16
|
79 PriorityQueue<C>
|
Chris@16
|
80 {
|
Chris@16
|
81 typedef typename C::handle_type handle_type;
|
Chris@16
|
82
|
Chris@16
|
83 BOOST_CONCEPT_USAGE(MutablePriorityQueue)
|
Chris@16
|
84 {
|
Chris@16
|
85 BOOST_CONCEPT_ASSERT((boost::Assignable<typename MutablePriorityQueue::handle_type>));
|
Chris@16
|
86
|
Chris@16
|
87 typename MutablePriorityQueue::value_type v;
|
Chris@16
|
88 typename MutablePriorityQueue::handle_type h = c.push(v);
|
Chris@16
|
89 typename MutablePriorityQueue::handle_type h2 = c.push(v);
|
Chris@16
|
90 c.update(h, v);
|
Chris@16
|
91 c.increase(h, v);
|
Chris@16
|
92 c.decrease(h, v);
|
Chris@16
|
93
|
Chris@16
|
94 c.update(h);
|
Chris@16
|
95 c.increase(h);
|
Chris@16
|
96 c.decrease(h);
|
Chris@16
|
97
|
Chris@16
|
98 equal = (h == h2);
|
Chris@16
|
99 not_equal = (h != h2);
|
Chris@16
|
100
|
Chris@16
|
101 h2 = h;
|
Chris@16
|
102 }
|
Chris@16
|
103
|
Chris@16
|
104 C c;
|
Chris@16
|
105 bool equal, not_equal;
|
Chris@16
|
106 };
|
Chris@16
|
107
|
Chris@16
|
108 }}
|
Chris@16
|
109
|
Chris@16
|
110 #endif /* BOOST_HEAP_CONCEPTS_HPP */
|