- queue[meta header]
- std[meta namespace]
- priority_queue[meta class]
- function[meta id-type]
explicit priority_queue(
const Compare& x = Compare(),
const Container& other = Container()); // (1) C++03まで
priority_queue(const Compare& x, const Container& other); // (2) C++11
explicit priority_queue(const Compare& x = Compare(),
Container&& = Container()); // (3) C++11
priority_queue(const priority_queue&); // (4) C++03
priority_queue(const priority_queue&) = default; // (4) C++11
template <class InputIterator>
priority_queue(InputIterator first, InputIterator last,
const Compare& x = Compare(),
const Container& other = Container()); // (5) C++03
template <class InputIterator>
priority_queue(InputIterator first, InputIterator last,
const Compare& x,
const Container& other); // (6) C++11
template <class InputIterator>
priority_queue(InputIterator first, InputIterator last,
const Compare& x = Compare(),
Container&& other = Container()); // (7) C++11
priority_queue(priority_queue&&) = default; // (8) C++11
template <class Alloc>
explicit priority_queue(const Alloc& alloc); // (9) C++11
template <class Alloc>
priority_queue(const Compare& x, const Alloc& alloc); // (10) C++11
template <class Alloc>
priority_queue(const Compare& x,
const Container& other,
const Alloc& alloc); // (11) C++11
template <class Alloc>
priority_queue(const Compare x&,
Container&& other,
const Alloc& alloc); // (12) C++11
template <class Alloc>
priority_queue(const priority_queue& que,
const Alloc& alloc); // (13) C++11
template <class Alloc>
priority_queue(priority_queue&& que,
const Alloc& alloc); // (14) C++11- (1) : デフォルトコンストラクタ
- (2) : 比較関数と、元となるコンテナのコピーから構築するコンストラクタ。
- (3) : デフォルトコンストラクタ。比較関数のコピーと、元となるコンテナをムーブして構築する。
- (4) : コピーコンストラクタ
- (5), (6), (7) : イテレータ範囲で優先順位付きキューを構築する。
- (8) : ムーブコンストラクタ
- (9) : アロケータを受け取るコンストラクタ
- (10) : 比較関数とアロケータを受け取るコンストラクタ
- (11) : 比較関数、元となるコンテナのコピー、アロケータを受け取るコンストラクタ
- (12) : 比較関数、元となるコンテナの一時オブジェクト、アロケータを受け取るコンストラクタ
- (13) : アロケータ指定でコピー構築する
- (14) : アロケータ指定でムーブ構築する
Compare型パラメータxが、狭義の弱順序で定義されていること。
- (1) :
- メンバ変数
compをxでコピー構築する。 - メンバ変数
cをotherでコピー構築する。 make_heap(c.begin(), c.end(), comp)を呼び出す。
- メンバ変数
- (2) :
- メンバ変数
compをxでコピー構築する。 - メンバ変数
cをotherでコピー構築する。 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)を呼び出す。
- メンバ変数
#include <iostream>
#include <queue>
#include <vector>
#include <string>
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);
}- que.empty()[link empty.md]
- que.top()[link top.md]
- que.pop()[link pop.md]
- std::move[link /reference/utility/move.md]
que3 :
que4 : 4 3 1
que5 : 5 4 3 2 1
- Clang: ??
- GCC:
- GCC, C++11 mode: 4.7.0(アロケータ付き初期化以外は使用可能)
- ICC: ??
- Visual C++: ??