std::is_heap_until
Min standard notice:
Header: <algorithm>
Examines the range [first,last) and finds the largest range beginning at first which is a heap.
# Declarations
template< class RandomIt >
RandomIt is_heap_until( RandomIt first, RandomIt last );
(since C++11) (constexpr since C++20)
template< class ExecutionPolicy, class RandomIt >
RandomIt is_heap_until( ExecutionPolicy&& policy,
RandomIt first, RandomIt last );
(since C++17)
template< class RandomIt, class Compare >
RandomIt is_heap_until( RandomIt first, RandomIt last, Compare comp );
(since C++11) (constexpr since C++20)
template< class ExecutionPolicy, class RandomIt, class Compare >
RandomIt is_heap_until( ExecutionPolicy&& policy,
RandomIt first, RandomIt last, Compare comp );
(since C++17)
# Parameters
first, last: the range of elements to examinepolicy: the execution policy to usecomp: comparison function object (i.e. an object that satisfies the requirements of Compare) which returns true if the first argument is less than the second. The signature of the comparison function should be equivalent to the following: bool cmp(const Type1& a, const Type2& b); While the signature does not need to have const&, the function must not modify the objects passed to it and must be able to accept all values of type (possibly const) Type1 and Type2 regardless of value category (thus, Type1& is not allowed, nor is Type1 unless for Type1 a move is equivalent to a copy(since C++11)). The types Type1 and Type2 must be such that an object of type RandomIt can be dereferenced and then implicitly converted to both of them.
# Return value
The last iterator it for which range [first,it) is a heap.
# Example
#include <algorithm>
#include <iostream>
#include <vector>
int main()
{
std::vector<int> v{3, 1, 4, 1, 5, 9};
std::make_heap(v.begin(), v.end());
// probably mess up the heap
v.push_back(2);
v.push_back(6);
auto heap_end = std::is_heap_until(v.begin(), v.end());
std::cout << "all of v: ";
for (const auto& i : v)
std::cout << i << ' ';
std::cout << '\n';
std::cout << "only heap: ";
for (auto i = v.begin(); i != heap_end; ++i)
std::cout << *i << ' ';
std::cout << '\n';
}