std::unordered_multimap
的推导指引
定义于头文件 <unordered_map> |
||
template< class InputIt, class Hash = std::hash<iter_key_t<InputIt>>, |
(1) | (自 C++17 起) |
template< class Key, class T, class Hash = std::hash<Key>, class Pred = std::equal_to<Key>, |
(2) | (自 C++17 起) |
template< class InputIt, class Alloc > unordered_multimap( InputIt, InputIt, typename /*见下文*/::size_type, Alloc ) |
(3) | (自 C++17 起) |
template< class InputIt, class Alloc > unordered_multimap( InputIt, InputIt, Alloc ) |
(4) | (自 C++17 起) |
template< class InputIt, class Hash, class Alloc > unordered_multimap( InputIt, InputIt, typename /*见下文*/::size_type, Hash, Alloc ) |
(5) | (自 C++17 起) |
template< class Key, class T, typename Alloc > unordered_multimap( std::initializer_list<std::pair<Key, T>>, |
(6) | (自 C++17 起) |
template< class Key, class T, typename Alloc > unordered_multimap( std::initializer_list<std::pair<Key, T>>, Alloc ) |
(7) | (自 C++17 起) |
template< class Key, class T, class Hash, class Alloc > unordered_multimap( std::initializer_list<std::pair<Key, T>>, |
(8) | (自 C++17 起) |
template< ranges::input_range R, class Hash = std::hash<range_key_t<R>>, |
(9) | (自 C++23 起) |
template< ranges::input_range R, class Alloc > unordered_multimap( std::from_range_t, R&&, |
(10) | (自 C++23 起) |
template< ranges::input_range R, class Alloc > unordered_multimap( std::from_range_t, R&&, Alloc ) |
(11) | (自 C++23 起) |
template< ranges::input_range R, class Hash, class Alloc > unordered_multimap( std::from_range_t, R&&, typename /* 见描述 */::size_type, |
(12) | (自 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 起) (仅为演示目的*) |
|
unordered_multimap
而提供,以允许从迭代器范围(重载 (1,3-5))和 std::initializer_list (重载 (2,6-8))进行推导。这些重载仅在 InputIt
满足 LegacyInputIterator ,Alloc
满足 Allocator ,Hash
和 Pred
都不满足 Allocator ,且 Hash
不是整型类型时参与重载决议。
注意:库确定类型不满足 LegacyInputIterator 的程度是未指定的,但至少整型类型不符合输入迭代器的条件。 同样,库确定类型不满足 Allocator 的程度是未指定的,但至少成员类型 Alloc::value_type
必须存在,且表达式 std::declval<Alloc&>().allocate(std::size_t{}) 当作未求值运算数处理时必须是良构的。
这些指引中的 size_type 形参类型指的是由推导指引推导出的类型的 size_type 成员类型。
[编辑] 注解
特性测试 宏 | 值 | Std | 特性 |
---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | 范围感知 构造和插入;重载 (9-12) |
[编辑] 示例
#include <unordered_map> int main() { // std::unordered_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::unordered_multimap m1 = {std::pair{"foo", 2}, {"bar", 3}}; // guide #2 std::unordered_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> |