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 InputIt > using /*iter-val-t*/ = |
(僅用於闡述*) | |
template< class InputIt > using /*iter-key-t*/ = |
(僅用於闡述*) | |
template< class InputIt > using /*iter-mapped-t*/ = |
(僅用於闡述*) | |
template< class InputIt > 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) |
[編輯] 示例
#include <map> int main() { // std::multimap m1 = {{"foo", 1}, {"bar", 2}}; // 错误:花括号初始化式列表无类型; // 不能从 {"foo", 1} 或 {"bar", 2} 推导 pair<const Key, T> std::multimap m1 = {std::pair{"foo", 2}, {"bar", 3}}; // 指引 #2 std::multimap m2(m1.begin(), m1.end()); // 指引 #1 }
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 出版時的行為 | 正確行為 |
---|---|---|---|
LWG 3025 | C++17 | 初始化式列表的指導 (2,4) 接受 std::pair<const Key, T> | 使用 std::pair<Key, T> |