std::priority_queue<T,Container,Compare>:: push_range
|
template
<
container-compatible-range
<
value_type
>
R
>
void push_range ( R && rg ) ; |
(C++23以降) | |
rg
の各要素のコピーを、以下のように
priority_queue
に挿入します:
-
c.
append_range
(
std::
forward
<
R
>
(
rg
)
)
それが有効な式である場合(すなわち、基盤となるコンテナ
c
が適切な
append_rangeメンバ関数を持つ場合)、または - ranges:: copy ( rg, std:: back_inserter ( c ) ) それ以外の場合。
その後、 ranges:: make_heap ( c, comp ) によってヒーププロパティを復元します。挿入後、 ranges:: is_heap ( c, comp ) は true となります。
範囲内の各イテレータは、 rg 正確に1回デリファレンスされます。
目次 |
パラメータ
| rg | - |
a
container compatible range
, that is, an
input_range
whose elements are convertible to
T
|
計算量
c. append_range の計算量に加えて、 ranges:: make_heap ( c, comp ) の計算量。
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | Ranges-aware 構築と挿入 |
例
#include <initializer_list> #include <queue> #include <version> #ifdef __cpp_lib_format_ranges #include <print> using std::println; #else #define FMT_HEADER_ONLY #include <fmt/ranges.h> using fmt::println; #endif int main() { std::priority_queue<int> adaptor; const auto rg = {1, 3, 2, 4}; #ifdef __cpp_lib_containers_ranges adaptor.push_range(rg); #else for (int e : rg) adaptor.push(e); #endif println("{}", adaptor); }
出力:
[4, 3, 2, 1]
関連項目
|
要素を挿入し、基となるコンテナをソートする
(公開メンバ関数) |