std::is_heap_until
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev t-dcl-rev-num ">
</tbody><tbody>
</tbody>
| ヘッダ <algorithm> で定義
|
||
| (1) | ||
template< class RandomIt > RandomIt is_heap_until( RandomIt first, RandomIt last ); |
(C++11以上) (C++20未満) |
|
template< class RandomIt > constexpr RandomIt is_heap_until( RandomIt first, RandomIt last ); |
(C++20以上) | |
template< class ExecutionPolicy, class RandomIt > RandomIt is_heap_until( ExecutionPolicy&& policy, RandomIt first, RandomIt last ); |
(2) | (C++17以上) |
| (3) | ||
template< class RandomIt, class Compare > RandomIt is_heap_until( RandomIt first, RandomIt last, Compare comp ); |
(C++11以上) (C++20未満) |
|
template< class RandomIt, class Compare > constexpr RandomIt is_heap_until( RandomIt first, RandomIt last, Compare comp ); |
(C++20以上) | |
template< class ExecutionPolicy, class RandomIt, class Compare > RandomIt is_heap_until( ExecutionPolicy&& policy, RandomIt first, RandomIt last, Compare comp ); |
(4) | (C++17以上) |
範囲 [first, last) を調べ、最大ヒープである最も大きな first から始まる範囲を探します。
1) 要素は
operator< を用いて比較されます。3) 要素は指定された二項比較関数
comp を用いて比較されます。2,4) (1,3) と同じですが、
policy に従って実行されます。 これらのオーバーロードは、 std::is_execution_policy_v<std::decay_t<ExecutionPolicy>> が true でなければ、オーバーロード解決に参加しません。引数
| first, last | - | 調べる要素の範囲 |
| policy | - | 使用する実行ポリシー。 詳細は実行ポリシーを参照してください |
| comp | - | 第1引数が第2引数より小さい場合に true を返す、比較関数オブジェクト (Compare の要件を満たすオブジェクト)。比較関数のシグネチャは以下と同等であるべきです。
シグネチャが |
| 型の要件 | ||
-RandomIt は LegacyRandomAccessIterator の要件を満たさなければなりません。
| ||
戻り値
最大ヒープである最も大きな first から始まる範囲の上限。 つまり、範囲 [first, it) が最大ヒープである最後のイテレータ it。
計算量
first と last の距離に比例。
例外
テンプレート引数 ExecutionPolicy を持つオーバーロードは以下のようにエラーを報告します。
- アルゴリズムの一部として呼び出された関数の実行が例外を投げ、
ExecutionPolicyが標準のポリシーのいずれかの場合は、 std::terminate が呼ばれます。 それ以外のあらゆるExecutionPolicyについては、動作は処理系定義です。 - アルゴリズムがメモリの確保に失敗した場合は、 std::bad_alloc が投げられます。
ノート
最大ヒープは以下の性質を持つ要素の範囲 [f,l) です。
N = l - fとしたとき、すべての0 < i < Nについてf[floor(が
)]i-1 2 f[i]より小さくない。std::push_heap()を使用して新しい要素を追加できる。std::pop_heap()を使用して最初の要素を削除できる。
例
Run this code
#include <iostream>
#include <algorithm>
#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 (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';
}
出力:
all of v: 9 5 4 1 1 3 2 6
only heap: 9 5 4 1 1 3 2
関連項目
(C++11) |
指定範囲が最大ヒープであるかどうか調べます (関数テンプレート) |