std::priority_queue の推論ガイド
| ヘッダー <queue>で定義されています |
||
| template< class Comp, class Container > priority_queue( Comp, Container ) |
(1) | (C++17以降) |
| template< class InputIt, class Comp = std::less</*iter-value-type*/<InputIt>>, |
(2) | (C++17以降) |
| template< class Comp, class Container, class Alloc > priority_queue( Comp, Container, Alloc ) |
(3) | (C++17以降) |
| template< class InputIt, class Alloc > priority_queue( InputIt, InputIt, Alloc ) |
(4) | (C++17以降) |
| template< class InputIt, class Comp, class Alloc > priority_queue( InputIt, InputIt, Comp, Alloc ) |
(5) | (C++17以降) |
| template< class InputIt, class Comp, class Container, class Alloc > priority_queue( InputIt, InputIt, Comp, Container, Alloc ) |
(6) | (C++17以降) |
| template< ranges::input_range R, class Comp = std::less<ranges::range_value_t<R>> > |
(7) | (C++23から) |
| template< ranges::input_range R, class Comp, class Alloc > priority_queue( std::from_range_t, R&&, Comp, Alloc ) |
(8) | (C++23から) |
| template< ranges::input_range R, class Alloc > priority_queue( std::from_range_t, R&&, Alloc ) |
(9) | (C++23から) |
std::priority_queue について、以下の推論ガイドが提供されています。
Itに対する typename std::iterator_traits<It>::value_type を表します。これらのオーバーロードは、以下の場合にのみオーバーロード解決に参加します。
-
InputItは LegacyInputIterator を満たし、 -
Compは Allocator を満たさず、 -
Containerは Allocator を満たさない場合。 - オーバーロード (4,5) については、(C++23以降)
Allocは Allocator を満たし、 - オーバーロード (3,6) については、std::uses_allocator_v<Container, Alloc> が true である場合。
注: ライブラリが型が LegacyInputIterator を満たさないと判断する範囲は未規定ですが、最小限として、整数型は入力イテレータとして適格ではありません。同様に、型が Allocator を満たさないと判断する範囲も未規定ですが、最小限として、メンバ型Alloc::value_typeが存在し、式 std::declval<Alloc&>().allocate(std::size_t{}) が評価されないオペランドとしてwell-formedである必要があります。
[編集] 注釈
| 機能テストマクロ | 値 | 規格 | 機能 |
|---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | Ranges対応の構築と挿入; オーバーロード (7-9) |
[編集] 例
#include <functional> #include <iostream> #include <queue> #include <vector> int main() { const std::vector<int> v = {1, 2, 3, 4}; std::priority_queue pq1{std::greater<int>{}, v}; // deduces std::priority_queue< // int, std::vector<int>, // std::greater<int>> for (; !pq1.empty(); pq1.pop()) std::cout << pq1.top() << ' '; std::cout << '\n'; std::priority_queue pq2{v.begin(), v.end()}; // deduces std::priority_queue<int> for (; !pq2.empty(); pq2.pop()) std::cout << pq2.top() << ' '; std::cout << '\n'; }
出力
1 2 3 4 4 3 2 1
[編集] 不具合報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 3506 | C++17 | イテレータとアロケータからの推論ガイドが欠落していました | 追加された |