Namespaces
Variants

std::queue<T,Container>::queue

ja.cppreference.net より

 
 
 
 
queue() : queue(Container()) {}
(1) (C++11以降)
explicit queue( const Container& cont = Container() );
(2) (C++11まで)
explicit queue( const Container& cont );
(C++11以降)
explicit queue( Container&& cont );
(3) (C++11以降)
queue( const queue& other );
(4) (暗黙に宣言)
queue( queue&& other );
(5) (C++11以降)
(暗黙に宣言)
template< class InputIt >
queue( InputIt first, InputIt last );
(6) (C++23以降)
template< class Alloc >
explicit queue( const Alloc& alloc );
(7) (C++11以降)
template< class Alloc >
queue( const Container& cont, const Alloc& alloc );
(8) (C++11以降)
template< class Alloc >
queue( Container&& cont, const Alloc& alloc );
(9) (C++11以降)
template< class Alloc >
queue( const queue& other, const Alloc& alloc );
(10) (C++11以降)
template< class Alloc >
queue( queue&& other, const Alloc& alloc );
(11) (C++11以降)
template< class InputIt, class Alloc >
queue( InputIt first, InputIt last, const Alloc& alloc );
(12) (C++23以降)
template< container-compatible-range<T> R>
queue( std::from_range_t, R&& rg );
(13) (C++23以降)
template< container-compatible-range<T> R, class Alloc >
queue( std::from_range_t, R&& rg, const Alloc& alloc );
(14) (C++23以降)

コンテナアダプタの新しい内部コンテナを様々なデータソースから構築します。

1) デフォルトコンストラクタ。コンテナを値初期化します。
2) 内部コンテナcをcontの内容でコピー構築します。 これはデフォルトコンストラクタでもあります。(C++11まで)
3) 内部コンテナcをstd::move(cont)からムーブ構築します。
4) コピーコンストラクタ。アダプタはother.cの内容でコピー構築されます。
5) ムーブコンストラクタ。アダプタはstd::move(other.c)で構築されます。
6) 内部コンテナcを範囲[first, last)の内容で構築します。このオーバーロードは、InputItがLegacyInputIteratorを満たす場合にのみオーバーロード解決に参加します。
7-12) これらのコンストラクタは、std::uses_allocator<Container, Alloc>::valueがtrueである場合、つまり内部コンテナがアロケータ対応コンテナ(queueで使用できるすべての標準ライブラリコンテナに当てはまります)である場合にのみオーバーロード解決に参加します。
7) allocをアロケータとして使用して内部コンテナを構築します。c(alloc)と同様です。
8) contの内容で、allocをアロケータとして使用して内部コンテナを構築します。c(cont, alloc)と同様です。
9) contの内容をムーブセマンティクスで、allocをアロケータとして使用して内部コンテナを構築します。c(std::move(cont), alloc)と同様です。
10) other.cの内容で、allocをアロケータとして使用してアダプタを構築します。c(other.c, alloc)と同様です。
11) otherの内容をムーブセマンティクスで、allocをアロケータとして使用してアダプタを構築します。c(std::move(other.c), alloc)と同様です。
12) 範囲[first, last)の内容で、allocをアロケータとして使用して内部コンテナを構築します。c(first, last, alloc)と同様です。このオーバーロードは、InputItがLegacyInputIteratorを満たす場合にのみオーバーロード解決に参加します。
13) ranges::to<Container>(std::forward<R>(rg))で内部コンテナを構築します。
14) ranges::to<Container>(std::forward<R>(rg), alloc)で内部コンテナを構築します。

パラメータ

alloc - 基盤となるコンテナのすべてのメモリ割り当てに使用するアロケータ
other - 基盤となるコンテナを初期化するためのソースとして使用する別のコンテナアダプタ
cont - 基盤となるコンテナを初期化するためのソースとして使用するコンテナ
first, last - 初期化に使用する要素のソース範囲を定義するイテレータのペア range
rg - コンテナ互換範囲、すなわち要素が T に変換可能な input_range
型要件
-
Alloc は Allocator の要件を満たさなければならない
-
Container は Container の要件を満たさなければならない。アロケータパラメータを取るコンストラクタは、 Container が AllocatorAwareContainer の要件を満たす場合にのみオーバーロード解決に参加する
-
InputIt は LegacyInputIterator の要件を満たさなければならない

計算量

ラップされたコンテナに対する対応する操作と同じです。

注記

機能テスト マクロ 値 標準 機能
__cpp_lib_adaptor_iterator_pair_constructor 202106L (C++23) std::queue および std::stack のイテレータペアコンストラクタ; オーバーロード ( 6 ) および ( 12 )
__cpp_lib_containers_ranges 202202L (C++23) レンジ対応 の構築と挿入; オーバーロード ( 13 ) および ( 14 )

例

#include <cassert>
#include <deque>
#include <iostream>
#include <memory>
#include <ranges>
#include <queue>
int main()
{
    std::queue<int> c1;
    c1.push(5);
    assert(c1.size() == 1);
    std::queue<int> c2(c1);
    assert(c2.size() == 1);
    std::deque<int> deq{3, 1, 4, 1, 5};
    std::queue<int> c3(deq); // オーバーロード (2)
    assert(c3.size() == 5);
# ifdef __cpp_lib_adaptor_iterator_pair_constructor
    const auto il = {2, 7, 1, 8, 2};
    std::queue<int> c4{il.begin(), il.end()}; // C++23, (6)
    assert(c4.size() == 5);
# endif
# if __cpp_lib_containers_ranges >= 202202L
    // C++23, オーバーロード (13)
    auto c5 = std::queue(std::from_range_t, std::ranges::iota(0, 42));
    assert(c5.size() == 42);
    // パイプ構文でも同じ効果、内部的にオーバーロード (13) を使用
    auto c6 = std::ranges::iota(0, 42) | std::ranges::to<std::queue>();
    assert(c6.size() == 42);
    std::allocator<int> alloc;
    // C++23, オーバーロード (14)
    auto c7 = std::queue(std::from_range_t, std::ranges::iota(0, 42), alloc);
    assert(c7.size() == 42);
    // パイプ構文でも同じ効果、内部的にオーバーロード (14) を使用
    auto c8 = std::ranges::iota(0, 42) | std::ranges::to<std::queue>(alloc);
    assert(c8.size() == 42);
# endif
}

欠陥報告

以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。

DR Applied to Behavior as published Correct behavior
P0935R0 C++11 default constructor was explicit made implicit

関連項目

コンテナアダプタに値を代入する
(公開メンバ関数)