std::map
的推导指引
定义于头文件 <map> |
||
template< class InputIt, class Comp = std::less<iter_key_t<InputIt>>, |
(1) | (since C++17) |
template< class Key, class T, |
(2) | (since C++17) |
template< class InputIt, class Alloc > map( InputIt, InputIt, Alloc ) |
(3) | (since C++17) |
template< class Key, class T, class Alloc > map( std::initializer_list<std::pair<Key, T>>, Alloc ) |
(4) | (since C++17) |
template< ranges::input_range R, class Compare = std::less<range_key_t<R>, class Alloc = std::allocator<range_to_alloc_t<R>> > |
(5) | (since C++23) |
template< ranges::input_range R, class Alloc > map( std::from_range_t, R&&, Alloc ) |
(6) | (since C++23) |
仅供演示的辅助类型别名 |
||
template< class InputIter > using iter_val_t = |
(仅作演示*) | |
template< class InputIter > using iter_key_t = |
(仅作演示*) | |
template< class InputIter > using iter_mapped_t = |
(仅作演示*) | |
template< class InputIter > using iter_to_alloc_t = |
(仅作演示*) | |
template< ranges::input_range Range > using range_key_t = |
(since C++23) (仅作演示*) |
|
template< ranges::input_range Range > using range_mapped_t = |
(since C++23) (仅作演示*) |
|
template< ranges::input_range Range > using range_to_alloc_t = |
(since C++23) (仅作演示*) |
|
这些重载仅在 InputIt
满足 LegacyInputIterator,Alloc
满足 Allocator,且 Comp
不满足 Allocator 时参与重载决议。
注意:库确定类型不满足 LegacyInputIterator 的程度是未指定的,但至少整型类型不符合输入迭代器的条件。同样,库确定类型不满足 Allocator 的程度是未指定的,但至少成员类型 Alloc::value_type
必须存在,并且表达式 std::declval<Alloc&>().allocate(std::size_t{}) 在被视为未求值操作数时必须是良构的。
[edit] 注释
特性测试 宏 | 值 | 标准 | 特性 |
---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | 范围感知的 构造和插入;重载 (5,6) |
[edit] 示例
[edit] 缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。
DR | 应用于 | 已发布行为 | 正确行为 |
---|---|---|---|
LWG 3025 | C++17 | initializer_list 指引接受 std::pair<const Key, T> | 使用 std::pair<Key, T> |