std::priority_queue<T,Container,Compare>:: priority_queue
|
priority_queue
(
)
:
priority_queue
(
Compare
(
)
, Container
(
)
)
{
}
|
(1) | (C++11以降) |
|
explicit
priority_queue
(
const
Compare
&
compare
)
: priority_queue ( compare, Container ( ) ) { } |
(2) | (C++11以降) |
| (3) | ||
|
explicit
priority_queue
(
const
Compare
&
compare
=
Compare
(
)
,
const Container & cont = Container ( ) ) ; |
(C++11まで) | |
|
priority_queue
(
const
Compare
&
compare,
const
Container
&
cont
)
;
|
(C++11以降) | |
|
priority_queue
(
const
Compare
&
compare, Container
&&
cont
)
;
|
(4) | (C++11以降) |
|
priority_queue
(
const
priority_queue
&
other
)
;
|
(5) | |
|
priority_queue
(
priority_queue
&&
other
)
;
|
(6) | (C++11以降) |
|
template
<
class
InputIt
>
priority_queue
(
InputIt first, InputIt last,
|
(7) | (C++11以降) |
| (8) | ||
|
template
<
class
InputIt
>
priority_queue
(
InputIt first, InputIt last,
|
(C++11まで) | |
|
template
<
class
InputIt
>
priority_queue
(
InputIt first, InputIt last,
|
(C++11以降) | |
|
template
<
class
InputIt
>
priority_queue
(
InputIt first, InputIt last,
|
(9) | (C++11以降) |
|
template
<
class
Alloc
>
explicit priority_queue ( const Alloc & alloc ) ; |
(10) | (C++11以降) |
|
template
<
class
Alloc
>
priority_queue ( const Compare & compare, const Alloc & alloc ) ; |
(11) | (C++11以降) |
|
template
<
class
Alloc
>
priority_queue
(
const
Compare
&
compare,
const
Container
&
cont,
|
(12) | (C++11以降) |
|
template
<
class
Alloc
>
priority_queue
(
const
Compare
&
compare, Container
&&
cont,
|
(13) | (C++11以降) |
|
template
<
class
Alloc
>
priority_queue ( const priority_queue & other, const Alloc & alloc ) ; |
(14) | (C++11以降) |
|
template
<
class
Alloc
>
priority_queue ( priority_queue && other, const Alloc & alloc ) ; |
(15) | (C++11以降) |
|
template
<
class
InputIt,
class
Alloc
>
priority_queue ( InputIt first, InputIt last, const Alloc & alloc ) ; |
(16) | (C++11以降) |
|
template
<
class
InputIt,
class
Alloc
>
priority_queue
(
InputIt first, InputIt last,
const
Compare
&
compare,
|
(17) | (C++11以降) |
|
template
<
class
InputIt,
class
Alloc
>
priority_queue
(
InputIt first, InputIt last,
const
Compare
&
compare,
|
(18) | (C++11以降) |
|
template
<
class
InputIt,
class
Alloc
>
priority_queue
(
InputIt first, InputIt last,
const
Compare
&
compare,
|
(19) | (C++11以降) |
|
template
<
container-compatible-range
<
T
>
R
>
priority_queue
(
std::
from_range_t
, R
&&
rg,
|
(20) | (C++23以降) |
|
template
<
container-compatible-range
<
T
>
R,
class
Alloc
>
priority_queue
(
std::
from_range_t
, R
&&
rg,
|
(21) | (C++23以降) |
|
template
<
container-compatible-range
<
T
>
R,
class
Alloc
>
priority_queue ( std:: from_range_t , R && rg, const Alloc & alloc ) ; |
(22) | (C++23以降) |
コンテナアダプタの基盤となる新しいコンテナを、様々なデータソースから構築します。
実装が型が LegacyInputIterator を満たすかどうかをチェックする方法は未規定であるが、整数型は拒否されることが要求されることに注意してください。
目次 |
パラメータ
| alloc | - | 基盤となるコンテナの全てのメモリ割り当てに使用するアロケータ |
| other | - | 基盤となるコンテナを初期化するためのソースとして使用する別のコンテナアダプタ |
| cont | - | 基盤となるコンテナを初期化するためのソースとして使用するコンテナ |
| compare | - | 基盤となる比較ファンクタを初期化するための比較関数オブジェクト |
| first, last | - | 初期化する要素の 範囲 を定義するイテレータのペア |
| rg | - |
コンテナ互換範囲
、すなわち要素が
T
に変換可能な
input_range
|
| 型要件 | ||
-
Alloc
は
Allocator
の要件を満たさなければならない。
|
||
-
Compare
は
Compare
の要件を満たさなければならない。
|
||
-
Container
は
Container
の要件を満たさなければならない。アロケータ拡張コンストラクタは、
Container
が
AllocatorAwareContainer
の要件を満たす場合にのみ定義される。
|
||
-
InputIt
は
LegacyInputIterator
の要件を満たさなければならない。
|
||
計算量
value_type
コンストラクタ呼び出し。ここで
N
は
cont.
size
(
)
である。
value_type
コンストラクタ呼び出し。ここで
N
は
cont.
size
(
)
、
M
は
std::
distance
(
first, last
)
である。
Alloc
が
other
のアロケータと等しく比較される場合は定数時間。
それ以外の場合は
other
のサイズに対して線形時間。
value_type
のコンストラクタ呼び出し(
Alloc
が
other
のアロケータと等しくない場合に発生)が発生します。ここで
N
は
cont.
size
(
)
であり、
M
は
std::
distance
(
first, last
)
です。
| このセクションは不完全です |
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | Ranges-aware 構築と挿入; オーバーロード ( 20-22 ) |
例
#include <complex> #include <functional> #include <iostream> #include <queue> #include <vector> int main() { std::priority_queue<int> pq1; pq1.push(5); std::cout << "pq1.size() = " << pq1.size() << '\n'; std::priority_queue<int> pq2 {pq1}; std::cout << "pq2.size() = " << pq2.size() << '\n'; std::vector<int> vec {3, 1, 4, 1, 5}; std::priority_queue<int> pq3 {std::less<int>(), vec}; std::cout << "pq3.size() = " << pq3.size() << '\n'; for (std::cout << "pq3 : "; !pq3.empty(); pq3.pop()) std::cout << pq3.top() << ' '; std::cout << '\n'; // カスタム比較関数を使用したデモ: using my_value_t = std::complex<double>; using my_container_t = std::vector<my_value_t>; auto my_comp = [](const my_value_t& z1, const my_value_t& z2) { return z2.real() < z1.real(); }; std::priority_queue<my_value_t, my_container_t, decltype(my_comp)> pq4{my_comp}; using namespace std::complex_literals; pq4.push(5.0 + 1i); pq4.push(3.0 + 2i); pq4.push(7.0 + 3i); for (; !pq4.empty(); pq4.pop()) { const auto& z = pq4.top(); std::cout << "pq4.top() = " << z << '\n'; } // TODO: C++23 レンジ対応コンストラクタ }
出力:
pq1.size() = 1 pq2.size() = 1 pq3.size() = 5 pq3 : 5 4 3 1 1 pq4.top() = (3,2) pq4.top() = (5,1) pq4.top() = (7,3)
欠陥報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用バージョン | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| P0935R0 | C++11 | デフォルトコンストラクタとコンストラクタ (4) がexplicitであった | 暗黙的(implicit)に変更 |
| LWG 3506 | C++11 | アロケータ拡張イテレータペアコンストラクタが欠落していた | 追加 |
| LWG 3522 | C++11 | イテレータペアコンストラクタの制約が欠落していた | 追加 |
| LWG 3529 | C++11 |
イテレータペアからの構築が
insert
を呼び出していた
|
イテレータペアからコンテナを構築する |
関連項目
|
コンテナアダプタに値を代入する
(公開メンバ関数) |