std::priority_queue::priority_queue
来自cppreference.com
< cpp | container | priority queue
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
explicit priority_queue( const Compare& compare = Compare(), const Container& cont = Container()); |
(1) | (至 C++11) (C++11 起) |
explicit priority_queue( const Compare& compare = Compare(), Container&& cont = Container()); |
(2) | (C++11 起) |
priority_queue( const priority_queue& other ); |
(3) | |
priority_queue( priority_queue&& other ); |
(4) | (C++11 起) |
template< class Alloc > explicit priority_queue( const Alloc& alloc ); |
(5) | (C++11 起) |
template< class Alloc > priority_queue( const Compare& compare, const Alloc& alloc ); |
(6) | (C++11 起) |
template< class Alloc > priority_queue( const Compare& compare, const Container& cont, |
(7) | (C++11 起) |
template< class Alloc > priority_queue( const Compare& compare, Container&& cont, |
(8) | (C++11 起) |
template< class Alloc > priority_queue( const priority_queue& other, const Alloc& alloc ); |
(9) | (C++11 起) |
template< class Alloc > priority_queue( priority_queue&& other, const Alloc& alloc ); |
(10) | (C++11 起) |
template< class InputIt > priority_queue( InputIt first, InputIt last, |
(11) | (C++11 起) |
template< class InputIt > priority_queue(InputIt first, InputIt last, |
(12) | (C++11 起) |
构建新的基础容器,容器适配器从各种数据源.
原文:
Constructs new underlying container of the container adaptor from a variety of data sources.
1) 这是默认的构造函数(至 C++11)|Copy-constructs the underlying container
c
with the contents of cont
. Copy-constructs the comparison functor comp
with the contents of compare
. Calls std::make_heap(c.begin(), c.end(), comp).}} This is also the default constructor (至 C++11)}}2)
移动构建的基本容器
c
std::move(cont)。移动构造比较函数comp
与std::move(compare)。调用std::make_heap(c.begin(), c.end(), comp)。这也是默认的构造函数(C++11 起)原文:
Move-constructs the underlying container
c
with std::move(cont). Move-constructs the comparison functor comp
with std::move(compare). Calls std::make_heap(c.begin(), c.end(), comp). This is also the default constructor (C++11 起)3)
4)
5-10)
下面的构造std::uses_allocator<container_type, Alloc>::value == true,也就是说,如果的基础容器是一个分配器感知的容器(适用于所有标准库容器),如果只定义.
原文:
The following constructors are only defined if std::uses_allocator<container_type, Alloc>::value == true, that is, if the underlying container is an allocator-aware container (true for all standard library containers).
5)
构造底层的容器,使用
alloc
作为分配器。有效地调用c(alloc)。 comp
is value-initialized.原文:
Constructs the underlying container using
alloc
as allocator. Effectively calls c(alloc). comp
is value-initialized.6)
构造底层的容器,使用
alloc
作为分配器。有效地调用c(alloc)。复制结构comp
从compare
.原文:
Constructs the underlying container using
alloc
as allocator. Effectively calls c(alloc). Copy-constructs comp
from compare
.7)
构造的基础容器
cont
的内容和使用alloc
作为分配器。有效地调用c(cont, alloc)。复制结构comp
从compare
.原文:
Constructs the underlying container with the contents of
cont
and using alloc
as allocator. Effectively calls c(cont, alloc). Copy-constructs comp
from compare
.8)
9)
构建适配器的
other.c
的内容,作为分配器和使用alloc
。有效地调用c(athor.c, alloc)。复制结构comp
从other.comp
.原文:
Constructs the adaptor with the contents of
other.c
and using alloc
as allocator. Effectively calls c(athor.c, alloc). Copy-constructs comp
from other.comp
.10)
11)
c
cont
和comp
从compare
复制结构。然后调用c.insert(c.end(), first, last);,然后调用std::make_heap(c.begin(), c.end(), comp);.原文:
Copy-constructs
c
from cont
and comp
from compare
. Then calls c.insert(c.end(), first, last);, and then calls std::make_heap(c.begin(), c.end(), comp);.12)
移动
c
从std::move(cont)
结构和comp
std::move(compare)
。然后调用c.insert(c.end(), first, last);,然后调用std::make_heap(c.begin(), c.end(), comp);.原文:
Move-constructs
c
from std::move(cont)
and comp
from std::move(compare)
. Then calls c.insert(c.end(), first, last);, and then calls std::make_heap(c.begin(), c.end(), comp);.目录 |
[编辑] 参数
alloc | - | 分配器使用的所有内存分配的基础容器
原文: allocator to use for all memory allocations of the underlying container |
other | - | 另一个容器适配器要用作源初始化基础容器
原文: another container adaptor to be used as source to initialize the underlying container |
cont | - | 容器被用作源初始化基础容器
原文: container to be used as source to initialize the underlying container |
compare | - | 比较函数对象初始化的基础比较函数
原文: the comparison function object to initialize the underlying comparison functor |
first, last | - | 初始化的元素范围
原文: range of elements to initialize with |
类型要求 | ||
-Alloc 必须满足 Allocator 的要求。
| ||
-Container 必须满足 Container 的要求。 The constructors (5-10) are only defined if Container meets the requirements of AllocatorAwareContainer
| ||
-InputIt 必须满足 InputIterator 的要求。
|
[编辑] 复杂度
1,3,5,6,8:线性
cont
或other
原文:
1, 3, 5, 6, 8: linear in
cont
or other
2,4,7,9:不变
本章尚未完成 |
[编辑] 示例
#include <queue> #include <deque> #include <iostream> int main() { std::priority_queue<int> c1; c1.push(5); std::cout << c1.size() << '\n'; std::priority_queue<int> c2(c1); std::cout << c2.size() << '\n'; std::deque<int> deq {3, 1, 4, 1, 5}; std::priority_queue<int> c3(std::less<int>(), deq); std::cout << c3.size() << '\n'; }
输出:
1 1 5
[编辑] 另请参阅
将值指派给容器适配器 原文: assigns values to the container adaptor (公共成员函数) |