std::multimap
的推导指引
定义于头文件 <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 > multimap( InputIt, InputIt, Alloc ) |
(3) | (自 C++17 起) |
template< class Key, class T, class Alloc > multimap( 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 > multimap( 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{}) 在被视为未求值操作数时必须是良构的。
[编辑] 注解
特性测试 宏 | 值 | Std | 特性 |
---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | 范围感知 构造和插入;重载 (5,6) |
[编辑] 示例
#include <map> int main() { // std::multimap m1 = {{"foo", 1}, {"bar", 2}}; // Error: braced-init-list has no type; cannot deduce // pair<Key, T> from {"foo", 1} or {"bar", 2} std::multimap m1 = {std::pair{"foo", 2}, {"bar", 3}}; // guide #2 std::multimap m2(m1.begin(), m1.end()); // guide #1 }
[编辑] 缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的 C++ 标准。
DR | 应用于 | 已发布行为 | 正确行为 |
---|---|---|---|
LWG 3025 | C++17 | initializer-list 指引接受 std::pair<const Key, T> | 使用 std::pair<Key, T> |