GeezerVison is showing cpprefjp.github.io — std::stack::コンストラクタ - cpprefjp C++日本語リファレンス
最終更新日時:
2026年08月27日 10時53分33秒 (JST)
Akira Takahashi
が更新
履歴
編集
function
<stack>
std:: stack:: コンストラクタ
// C++98まで
explicit stack ( const Container & cont = Container ()); // (1), (2)
// C++11以降 C++17まで
explicit stack ( const Container & cont ); // (2)
explicit stack ( Container && cont = Container ()); // (1), (3)
// C++20以降
stack () : stack ( Container ()) {} // (1)
constexpr stack () : stack ( Container ()) {} // (1) C++26
explicit stack ( const Container & ); // (2)
constexpr explicit stack ( const Container & ); // (2) C++26
explicit stack ( Container && ); // (3)
constexpr explicit stack ( Container && ); // (3) C++26
template < class InputIterator >
stack ( InputIterator first , InputIterator last ); // (4) C++23
template < class InputIterator >
constexpr stack ( InputIterator first , InputIterator last ); // (4) C++26
template < class Allocator >
explicit stack ( const Allocator & alloc ); // (5) C++11
template < class Allocator >
constexpr explicit stack ( const Allocator & alloc ); // (5) C++26
template < class Allocator >
stack ( const Container & cont , const Allocator & alloc ); // (6) C++11
template < class Allocator >
constexpr stack ( const Container & cont , const Allocator & alloc ); // (6) C++26
template < class Allocator >
stack ( Container && cont , const Allocator & alloc ); // (7) C++11
template < class Allocator >
constexpr stack ( Container && cont , const Allocator & alloc ); // (7) C++26
template < class Allocator >
stack ( const stack & st , const Allocator & alloc ); // (8) C++11
template < class Allocator >
constexpr stack ( const stack & st , const Allocator & alloc ); // (8) C++26
template < class Allocator >
stack ( stack && st , const Allocator & alloc ); // (9) C++11
template < class Allocator >
constexpr stack ( stack && st , const Allocator & alloc ); // (9) C++26
template < class InputIterator , class Alloc >
stack ( InputIterator first , InputIterator last , const Alloc & ); // (10) C++23
template < class InputIterator , class Alloc >
constexpr stack ( InputIterator first , InputIterator last , const Alloc & ); // (10) C++26
template < container - compatible - range < T > R >
stack ( from_range_t , R && rg ); // (11) C++23
template < container - compatible - range < T > R >
constexpr stack ( from_range_t , R && rg ); // (11) C++26
template < container - compatible - range < T > R , class Alloc >
stack ( from_range_t , R && rg , const Alloc & alloc ); // (12) C++23
template < container - compatible - range < T > R , class Alloc >
constexpr stack ( from_range_t , R && rg , const Alloc & alloc ); // (12) C++26
概要
(1) : デフォルトコンストラクタ。
(2) : 元となるコンテナのコピーを受け取るコンストラクタ。
(3) : 元となるコンテナの一時オブジェクトをムーブで受け取るコンストラクタ。
(4) : 元となるコンテナをイテレータペアで受け取るコンストラクタ。
(5) : アロケータを受け取るコンストラクタ。
(6) : 元となるコンテナのコピーとアロケータを受け取るコンストラクタ。
(7) : 元となるコンテナの一時オブジェクトとアロケータを受け取るコンストラクタ。
(8) : アロケータを受け取るコピーコンストラクタ。
(9) : アロケータを受け取るムーブコンストラクタ。
(10) : 元となるコンテナのイテレータペアとアロケータを受け取るコンストラクタ。
(11) : 元となるRangeを受け取るコンストラクタ。
(12) : 元となるRangeとアロケータを受け取るコンストラクタ。
効果
(2) : メンバ変数cをcontのコピーで初期化する。
(3) : メンバ変数cをstd::move (cont)で初期化する。
(4) : メンバ変数cを2つの引数first, lastで初期化する。
(5) : メンバ変数cのメモリアロケートにallocを使用する。
(6) : メンバ変数cをContainer(cont, alloc)で初期化する。
(7) : メンバ変数cをContainer(std::move (cont), alloc)で初期化する。
(8) : メンバ変数cをContainer(st.c, alloc)で初期化する。
(9) : メンバ変数cをContainer(std::move (st.c), alloc)で初期化する。
(10) : メンバ変数cを3つの引数first, last, allocで初期化する。
(11) : メンバ変数cをContainer(from_range, rg)で初期化する。
(12) : メンバ変数cをContainer(from_range, rg, alloc)で初期化する。
例
出力
3 2 1
参照