GeezerVison is showing cpprefjp.github.io — std::priority_queue::コンストラクタ - cpprefjp C++日本語リファレンス
最終更新日時:
2026年09月19日 21時31分51秒 (JST)
rotarymars
が更新
履歴
編集
function
<queue>
std:: priority_queue:: コンストラクタ
explicit
priority_queue ( const Compare & x = Compare (),
const Container & other = Container ()); // (1) C++98
explicit
priority_queue ( const Compare & x = Compare (),
Container && y = Container ()); // (1) C++11
priority_queue ()
: priority_queue ( Compare ()) {} // (1) C++20
constexpr
priority_queue ()
: priority_queue ( Compare ()) {} // (1) C++26
explicit
priority_queue ( const Compare & x )
: priority_queue ( x , Container ()) {} // (2) C++20
constexpr explicit
priority_queue ( const Compare & x )
: priority_queue ( x , Container ()) {} // (2) C++26
priority_queue ( const Compare & x , const Container & other ); // (3) C++11
constexpr priority_queue ( const Compare & x , const Container & other ); // (3) C++26
priority_queue ( const priority_queue & ); // (4) C++98
priority_queue ( const priority_queue & ) = default ; // (4) C++11
constexpr priority_queue ( const priority_queue & ) = default ; // (4) C++26
template < class InputIterator >
priority_queue ( InputIterator first ,
InputIterator last ,
const Compare & x = Compare (),
const Container & other = Container ()); // (5) C++98
template < class InputIterator >
constexpr
priority_queue ( InputIterator first ,
InputIterator last ,
const Compare & x = Compare (),
const Container & other = Container ()); // (5) C++26
template < class InputIterator >
priority_queue ( InputIterator first ,
InputIterator last ,
const Compare & x ,
const Container & other ); // (6) C++11
template < class InputIterator >
constexpr
priority_queue ( InputIterator first ,
InputIterator last ,
const Compare & x ,
const Container & other ); // (6) C++26
template < class InputIterator >
priority_queue ( InputIterator first ,
InputIterator last ,
const Compare & x = Compare (),
Container && other = Container ()); // (7) C++11
template < class InputIterator >
constexpr
priority_queue ( InputIterator first ,
InputIterator last ,
const Compare & x = Compare (),
Container && other = Container ()); // (7) C++26
priority_queue ( priority_queue && ) = default ; // (8) C++11
constexpr priority_queue ( priority_queue && ) = default ; // (8) C++26
template < class Alloc >
explicit priority_queue ( const Alloc & alloc ); // (9) C++11
template < class Alloc >
constexpr explicit priority_queue ( const Alloc & alloc ); // (9) C++26
template < class Alloc >
priority_queue ( const Compare & x , const Alloc & alloc ); // (10) C++11
template < class Alloc >
constexpr priority_queue ( const Compare & x , const Alloc & alloc ); // (10) C++26
template < class Alloc >
priority_queue ( const Compare & x ,
const Container & other ,
const Alloc & alloc ); // (11) C++11
template < class Alloc >
constexpr
priority_queue ( const Compare & x ,
const Container & other ,
const Alloc & alloc ); // (11) C++26
template < class Alloc >
priority_queue ( const Compare & x ,
Container && other ,
const Alloc & alloc ); // (12) C++11
template < class Alloc >
constexpr
priority_queue ( const Compare & x ,
Container && other ,
const Alloc & alloc ); // (12) C++26
template < class Alloc >
priority_queue ( const priority_queue & que ,
const Alloc & alloc ); // (13) C++11
template < class Alloc >
constexpr
priority_queue ( const priority_queue & que ,
const Alloc & alloc ); // (13) C++26
template < class Alloc >
priority_queue ( priority_queue && que ,
const Alloc & alloc ); // (14) C++11
template < class Alloc >
constexpr
priority_queue ( priority_queue && que ,
const Alloc & alloc ); // (14) C++26
template < class InputIterator , class Alloc >
priority_queue ( InputIterator first ,
InputIterator last ,
const Compare & x ,
const Alloc & alloc ); // (15) C++23
template < class InputIterator , class Alloc >
constexpr
priority_queue ( InputIterator first ,
InputIterator last ,
const Compare & x ,
const Alloc & alloc ); // (15) C++26
template < class InputIterator , class Alloc >
priority_queue ( InputIterator first ,
InputIterator last ,
const Compare & x ,
const Container & other ,
const Alloc & alloc ); // (16) C++23
template < class InputIterator , class Alloc >
constexpr
priority_queue ( InputIterator first ,
InputIterator last ,
const Compare & x ,
const Container & other ,
const Alloc & alloc ); // (16) C++26
template < class InputIterator , class Alloc >
priority_queue ( InputIterator first ,
InputIterator last ,
const Compare & x ,
Container && other ,
const Alloc & alloc ); // (17) C++23
template < class InputIterator , class Alloc >
constexpr
priority_queue ( InputIterator first ,
InputIterator last ,
const Compare & x ,
Container && other ,
const Alloc & alloc ); // (17) C++26
template < container - compatible - range < T > R >
priority_queue ( from_range_t , R && rg ,
const Compare & x = Compare ()); // (18) C++23
template < container - compatible - range < T > R >
constexpr
priority_queue ( from_range_t , R && rg ,
const Compare & x = Compare ()); // (18) C++26
template < container - compatible - range < T > R , class Alloc >
priority_queue ( from_range_t , R && rg ,
const Compare & x ,
const Alloc & alloc ); // (19) C++23
template < container - compatible - range < T > R , class Alloc >
constexpr
priority_queue ( from_range_t , R && rg ,
const Compare & x ,
const Alloc & alloc ); // (19) C++26
template < container - compatible - range < T > R , class Alloc >
priority_queue ( from_range_t , R && rg ,
const Alloc & alloc ); // (20) C++23
template < container - compatible - range < T > R , class Alloc >
constexpr
priority_queue ( from_range_t , R && rg ,
const Alloc & alloc ); // (20) C++26
概要
(1) : デフォルトコンストラクタ
C++98 : 比較関数と元となるコンテナをコピーして構築する。
C++11 : 比較関数をコピー、元となるコンテナをムーブして構築する。
C++20 : (2)に委譲。
(2) : 比較関数のコピーと元となるコンテナをデフォルト構築して構築するコンストラクタ。
(3) : 比較関数と、元となるコンテナのコピーから構築するコンストラクタ。
(4) : コピーコンストラクタ
(5), (6), (7) : イテレータ範囲で優先順位付きキューを構築する。
(8) : ムーブコンストラクタ
(9) : アロケータを受け取るコンストラクタ
(10) : 比較関数とアロケータを受け取るコンストラクタ
(11) : 比較関数、元となるコンテナのコピー、アロケータを受け取るコンストラクタ
(12) : 比較関数、元となるコンテナの一時オブジェクト、アロケータを受け取るコンストラクタ
(13) : アロケータ指定でコピー構築する
(14) : アロケータ指定でムーブ構築する
(15), (16), (17) : アロケータ指定でイテレータ範囲から優先順位付きキューを構築する
(18), (19), (20) : Rangeから優先順位付きキューを構築する
要件
Compare型パラメータxが、狭義の弱順序 で定義されていること。
テンプレートパラメータ制約
(5), (6), (7), (15), (16), (17) :
C++23 : InputIteratorが入力イテレータの要件を満たすこと。
効果
(1) :
C++98
メンバ変数compをxでコピー構築する。
メンバ変数cをotherでコピー構築する。
make_heap (c.begin(), c.end(), comp)を呼び出す。
C++11
メンバ変数compをxでコピー構築する。
メンバ変数cをyでムーブ構築する。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(3) :
メンバ変数compをxでコピー構築する。
メンバ変数cをotherでコピー構築する。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(5):
メンバ変数compをxでコピー構築する。
メンバ変数cをotherでコピー構築する。
c.insert(c.end(), first, last)を呼び出す。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(6) :
c.insert(c.end(), first, last)を呼び出す。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(7):
メンバ変数compをxでコピー構築する。
メンバ変数cをotherでムーブ構築する。
c.insert(c.end(), first, last)を呼び出す。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(9) :
メンバ変数cのメモリアロケートにallocを使用する。
メンバ変数compを値初期化する。
(10) :
メンバ変数cのメモリアロケートにallocを使用する。
メンバ変数compをxで初期化する。
(11) :
メンバ変数compをxでコピー構築する。
メンバ変数cをotherでコピー構築する。
メンバ変数cのメモリアロケートにallocを使用する。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(12) :
メンバ変数compをxでコピー構築する。
メンバ変数cをotherでムーブ構築する。
メンバ変数cのメモリアロケートにallocを使用する。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(13) :
メンバ変数compをque.compでコピー構築する。
メンバ変数cをque.cでコピー構築する。
メンバ変数cのメモリアロケートにallocを使用する。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(14) :
メンバ変数compをque.compでムーブ構築する。
メンバ変数cをque.cでムーブ構築する。
メンバ変数cのメモリアロケートにallocを使用する。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(15) :
メンバ変数compをxでコピー構築する。
メンバ変数cのメモリアロケートにallocを使用する。
c.insert(c.end(), first, last)を呼び出す。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(16) :
メンバ変数compをxでコピー構築する。
メンバ変数cをotherでコピー構築する。
メンバ変数cのメモリアロケートにallocを使用する。
c.insert(c.end(), first, last)を呼び出す。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(17) :
メンバ変数compをxでコピー構築する。
メンバ変数cをotherでムーブ構築する。
メンバ変数cのメモリアロケートにallocを使用する。
c.insert(c.end(), first, last)を呼び出す。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(18) :
メンバ変数compをxでコピー構築する。
c.insert(c.end(), ranges::begin(rg), ranges::end(rg))を呼び出す。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(19) :
メンバ変数compをxでコピー構築する。
メンバ変数cのメモリアロケートにallocを使用する。
c.insert(c.end(), ranges::begin(rg), ranges::end(rg))を呼び出す。
make_heap (c.begin(), c.end(), comp)を呼び出す。
(20) :
メンバ変数compを値初期化する。
メンバ変数cのメモリアロケートにallocを使用する。
c.insert(c.end(), ranges::begin(rg), ranges::end(rg))を呼び出す。
make_heap (c.begin(), c.end(), comp)を呼び出す。
例
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <utility>
template < class PriorityQueue >
void pop_print ( const std::string & name , PriorityQueue & que )
{
std::cout << name << " : " ;
while ( ! que.empty() ) {
std::cout << que.top() << ' ' ;
que.pop() ;
}
std::cout << std::endl ;
}
int main ()
{
// デフォルト構築
std :: priority_queue < int > que1 ;
// que1からコピー構築
std :: priority_queue < int > que2 = que1 ;
// que2からムーブ構築
std :: priority_queue < int > que3 = std::move ( que2 );
// イテレータ範囲から構築
const std::vector < int > v = { 3 , 1 , 4 };
std :: priority_queue < int > que4 ( v.begin() , v.end() );
// イテレータ範囲、比較関数オブジェクト、コンテナから構築
const std::vector < int > v2 = { 5 , 2 };
std :: priority_queue < int > que5 ( v.begin() , v.end() , {}, v2 );
pop_print ( "que3" , que3 );
pop_print ( "que4" , que4 );
pop_print ( "que5" , que5 );
}
出力
que3 :
que4 : 4 3 1
que5 : 5 4 3 2 1
処理系
参照