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> |