1 // Copyright Neil Groves 2009. Use, modification and
2 // distribution is subject to the Boost Software License, Version
3 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
7 // For more information, see http://www.boost.org/libs/range/
9 #ifndef BOOST_RANGE_ALGORITHM_HEAP_ALGORITHM_HPP_INCLUDED
10 #define BOOST_RANGE_ALGORITHM_HEAP_ALGORITHM_HPP_INCLUDED
12 #include <boost/concept_check.hpp>
13 #include <boost/range/begin.hpp>
14 #include <boost/range/end.hpp>
15 #include <boost/range/concepts.hpp>
23 /// \brief template function push_heap
25 /// range-based version of the push_heap std algorithm
27 /// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
28 /// \pre Compare is a model of the BinaryPredicateConcept
29 template<class RandomAccessRange>
30 inline RandomAccessRange& push_heap(RandomAccessRange& rng)
32 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
33 std::push_heap(boost::begin(rng), boost::end(rng));
38 template<class RandomAccessRange>
39 inline const RandomAccessRange& push_heap(const RandomAccessRange& rng)
41 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
42 std::push_heap(boost::begin(rng), boost::end(rng));
47 template<class RandomAccessRange, class Compare>
48 inline RandomAccessRange& push_heap(RandomAccessRange& rng, Compare comp_pred)
50 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
51 std::push_heap(boost::begin(rng), boost::end(rng), comp_pred);
56 template<class RandomAccessRange, class Compare>
57 inline const RandomAccessRange& push_heap(const RandomAccessRange& rng, Compare comp_pred)
59 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
60 std::push_heap(boost::begin(rng), boost::end(rng), comp_pred);
64 /// \brief template function pop_heap
66 /// range-based version of the pop_heap std algorithm
68 /// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
69 /// \pre Compare is a model of the BinaryPredicateConcept
70 template<class RandomAccessRange>
71 inline RandomAccessRange& pop_heap(RandomAccessRange& rng)
73 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
74 std::pop_heap(boost::begin(rng), boost::end(rng));
79 template<class RandomAccessRange>
80 inline const RandomAccessRange& pop_heap(const RandomAccessRange& rng)
82 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
83 std::pop_heap(boost::begin(rng), boost::end(rng));
88 template<class RandomAccessRange, class Compare>
89 inline RandomAccessRange& pop_heap(RandomAccessRange& rng, Compare comp_pred)
91 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
92 std::pop_heap(boost::begin(rng), boost::end(rng), comp_pred);
97 template<class RandomAccessRange, class Compare>
98 inline const RandomAccessRange& pop_heap(const RandomAccessRange& rng, Compare comp_pred)
100 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
101 std::pop_heap(boost::begin(rng), boost::end(rng), comp_pred);
105 /// \brief template function make_heap
107 /// range-based version of the make_heap std algorithm
109 /// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
110 /// \pre Compare is a model of the BinaryPredicateConcept
111 template<class RandomAccessRange>
112 inline RandomAccessRange& make_heap(RandomAccessRange& rng)
114 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
115 std::make_heap(boost::begin(rng), boost::end(rng));
120 template<class RandomAccessRange>
121 inline const RandomAccessRange& make_heap(const RandomAccessRange& rng)
123 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
124 std::make_heap(boost::begin(rng), boost::end(rng));
129 template<class RandomAccessRange, class Compare>
130 inline RandomAccessRange& make_heap(RandomAccessRange& rng, Compare comp_pred)
132 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
133 std::make_heap(boost::begin(rng), boost::end(rng), comp_pred);
138 template<class RandomAccessRange, class Compare>
139 inline const RandomAccessRange& make_heap(const RandomAccessRange& rng, Compare comp_pred)
141 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
142 std::make_heap(boost::begin(rng), boost::end(rng), comp_pred);
146 /// \brief template function sort_heap
148 /// range-based version of the sort_heap std algorithm
150 /// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
151 /// \pre Compare is a model of the BinaryPredicateConcept
152 template<class RandomAccessRange>
153 inline RandomAccessRange& sort_heap(RandomAccessRange& rng)
155 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
156 std::sort_heap(boost::begin(rng), boost::end(rng));
161 template<class RandomAccessRange>
162 inline const RandomAccessRange& sort_heap(const RandomAccessRange& rng)
164 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
165 std::sort_heap(boost::begin(rng), boost::end(rng));
170 template<class RandomAccessRange, class Compare>
171 inline RandomAccessRange& sort_heap(RandomAccessRange& rng, Compare comp_pred)
173 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
174 std::sort_heap(boost::begin(rng), boost::end(rng), comp_pred);
179 template<class RandomAccessRange, class Compare>
180 inline const RandomAccessRange& sort_heap(const RandomAccessRange& rng, Compare comp_pred)
182 BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
183 std::sort_heap(boost::begin(rng), boost::end(rng), comp_pred);
188 using range::push_heap;
189 using range::pop_heap;
190 using range::make_heap;
191 using range::sort_heap;
194 #endif // include guard