std::map
的推导指南
定义于头文件 <map> |
||
template< class InputIt, class Comp = std::less<iter_key_t<InputIt>>, |
(1) | (C++17 起) |
template< class Key, class T, |
(2) | (C++17 起) |
template< class InputIt, class Alloc > map( InputIt, InputIt, Alloc ) |
(3) | (C++17 起) |
template< class Key, class T, class Alloc > map( std::initializer_list<std::pair<Key, T>>, Alloc ) |
(4) | (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) | (C++23 起) |
template< ranges::input_range R, class Alloc > map( std::from_range_t, R&&, Alloc ) |
(6) | (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 = |
(C++23 起) (仅作说明*) |
|
template< ranges::input_range Range > using range_mapped_t = |
(C++23 起) (仅作说明*) |
|
template< ranges::input_range Range > using range_to_alloc_t = |
(C++23 起) (仅作说明*) |
|
这些重载只有在 InputIt
满足 LegacyInputIterator、Alloc
满足 Allocator 且 Comp
不满足 Allocator 时才参与重载决议。
注意:库确定类型不满足 LegacyInputIterator 的程度未指定,但至少整型不符合输入迭代器的条件。同样,它确定类型不满足 Allocator 的程度也未指定,但至少成员类型 Alloc::value_type
必须存在,并且表达式 std::declval<Alloc&>().allocate(std::size_t{}) 在作为未求值操作数时必须格式良好。
[编辑] 注解
特性测试宏 | 值 | 标准 | 特性 |
---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | 范围感知构造和插入;重载 (5,6) |
[编辑] 示例
[编辑] 缺陷报告
下列更改行为的缺陷报告追溯地应用于以前出版的 C++ 标准。
缺陷报告 | 应用于 | 发布时的行为 | 正确的行为 |
---|---|---|---|
LWG 3025 | C++17 | initializer-list 推导指南使用 std::pair<const Key, T> | 使用 std::pair<Key, T> |