function template
<algorithm>
std::is_heap_until default (1)template <class RandomAccessIterator> RandomAccessIterator is_heap_until (RandomAccessIterator first, RandomAccessIterator last);custom (2)
template <class RandomAccessIterator, class Compare> RandomAccessIterator is_heap_until (RandomAccessIterator first, RandomAccessIterator last Compare comp);
Find first element not in heap order
Returns an iterator to the first element in the range[first,last)
which is not in a valid position if the range is considered a heap (as if constructed with make_heap).
The range between first and the iterator returned is a heap.
If the entire range is a valid heap, the function returns last.
The elements are compared using operator<
for the first version, and comp for the second.
[first,last)
, which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
bool
. The value returned indicates whether the element passed as first argument is considered to go before the second in the specific strict weak ordering it defines.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// is_heap example
#include <iostream> // std::cout
#include <algorithm> // std::is_heap_until, std::sort, std::reverse
#include <vector> // std::vector
int main () {
std::vector<int> foo {2,6,9,3,8,4,5,1,7};
std::sort(foo.begin(),foo.end());
std::reverse(foo.begin(),foo.end());
auto last = std::is_heap_until (foo.begin(),foo.end());
std::cout << "The " << (last-foo.begin()) << " first elements are a valid heap:";
for (auto it=foo.begin(); it!=last; ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
The 9 first elements are a valid heap: 9 8 7 6 5 4 3 2 1
[first,last)
are accessed.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4