deduction guides for
std::priority_queue
|
定义于头文件
<queue>
|
||
|
template
<
class
Comp,
class
Container
>
priority_queue
(
Comp, Container
)
|
(1) | (C++17 起) |
|
template
<
class
InputIt,
class
Comp
=
std::
less
<
/*iter-val-t*/
<
InputIt
>>
,
|
(2) | (C++17 起) |
|
template
<
class
Comp,
class
Container,
class
Alloc
>
priority_queue
(
Comp, Container, Alloc
)
|
(3) | (C++17 起) |
|
template
<
class
InputIt,
class
Alloc
>
priority_queue
(
InputIt, InputIt, Alloc
)
std:: less < /*iter-val-t*/ < InputIt >>> ; |
(4) | (C++17 起) |
|
template
<
class
InputIt,
class
Comp,
class
Alloc
>
priority_queue
(
InputIt, InputIt, Comp, Alloc
)
|
(5) | (C++17 起) |
|
template
<
class
InputIt,
class
Comp,
class
Container,
class
Alloc
>
priority_queue
(
InputIt, InputIt, Comp, Container, Alloc
)
|
(6) | (C++17 起) |
|
template
<
ranges::
input_range
R,
class
Comp
=
std::
less
<
ranges::
range_value_t
<
R
>>
>
|
(7) | (C++23 起) |
|
template
<
ranges::
input_range
R,
class
Comp,
class
Alloc
>
priority_queue
(
std::
from_range_t
, R
&&
, Comp, Alloc
)
|
(8) | (C++23 起) |
|
template
<
ranges::
input_range
R,
class
Alloc
>
priority_queue
(
std::
from_range_t
, R
&&
, Alloc
)
|
(9) | (C++23 起) |
|
仅用于说明的辅助类型别名
|
||
|
template
<
class
InputIt
>
using
/*iter-val-t*/
=
|
为 std::priority_queue 提供了以下 推导指引 :
这些重载仅在以下情况下参与重载决议:
-
InputIt满足 LegacyInputIterator 要求, -
Comp不满足 Allocator 要求, -
Container不满足 Allocator 要求, -
对于重载
(
4,5
)
,
(C++23 起)
Alloc满足 Allocator 要求,且 - 对于重载 ( 3,6 ) , std:: uses_allocator_v < Container, Alloc > 为 true 。
注意:库判定某个类型不满足
LegacyInputIterator
要求的程度是未指定的,但至少整型类型不符合输入迭代器的要求。同样地,库判定某个类型不满足
Allocator
要求的程度也是未指定的,但至少要求成员类型
Alloc::value_type
必须存在,且表达式
std::
declval
<
Alloc
&
>
(
)
.
allocate
(
std::
size_t
{
}
)
在被视为未求值操作数时必须保持良构。
注释
| 功能测试 宏 | 值 | 标准 | 功能 |
|---|---|---|---|
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | 支持范围 的构造与插入;重载版本 ( 7-9 ) |
示例
#include <functional> #include <iostream> #include <queue> #include <vector> int main() { const std::vector<int> v = {1, 2, 3, 4}; std::priority_queue pq1{std::greater<int>{}, v}; // 推导为 std::priority_queue< // int, std::vector<int>, // std::greater<int>> for (; !pq1.empty(); pq1.pop()) std::cout << pq1.top() << ' '; std::cout << '\n'; std::priority_queue pq2{v.begin(), v.end()}; // 推导为 std::priority_queue<int> for (; !pq2.empty(); pq2.pop()) std::cout << pq2.top() << ' '; std::cout << '\n'; }
输出:
1 2 3 4 4 3 2 1
缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的C++标准。
| 缺陷报告 | 适用范围 | 发布时行为 | 修正后行为 |
|---|---|---|---|
| LWG 3506 | C++17 | 缺少来自迭代器和分配器的推导指引 | 已添加, ( 4-6 ) |