std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::flat_map
flat_map() : flat_map(key_compare()) { } |
(1) | (C++23 起) |
template< class Allocator > flat_map( const flat_map&, const Allocator& alloc ); |
(2) | (C++23 起) |
template< class Allocator > flat_map( flat_map&&, const Allocator& alloc ); |
(3) | (C++23 起) |
flat_map( key_container_type key_cont, mapped_container_type mapped_cont, const key_compare& comp = key_compare() ); |
(4) | (C++23 起) |
template< class Allocator > flat_map( const key_container_type& key_cont, |
(5) | (C++23 起) |
template< class Allocator > flat_map( const key_container_type& key_cont, |
(6) | (C++23 起) |
flat_map( std::sorted_unique_t, key_container_type key_cont, mapped_container_type mapped_cont, |
(7) | (C++23 起) |
template< class Allocator > flat_map( std::sorted_unique_t, const key_container_type& key_cont, |
(8) | (C++23 起) |
template< class Allocator > flat_map( std::sorted_unique_t, const key_container_type& key_cont, |
(9) | (C++23 起) |
explicit flat_map( const key_compare& comp ) : c(), compare(comp) { } |
(10) | (C++23 起) |
template< class Allocator > flat_map( const key_compare& comp, const Allocator& alloc ); |
(11) | (C++23 起) |
template< class Allocator > explicit flat_map( const Allocator& alloc ); |
(12) | (C++23 起) |
template< class InputIter > flat_map( InputIter first, InputIter last, |
(13) | (C++23 起) |
template< class InputIter, class Allocator > flat_map( InputIter first, InputIter last, |
(14) | (C++23 起) |
template< class InputIter, class Allocator > flat_map( InputIter first, InputIter last, const Allocator& alloc ); |
(15) | (C++23 起) |
template< container-compatible-range<value_type> R > flat_map( std::from_range_t, R&& rg, const key_compare& comp ) |
(16) | (C++23 起) |
template< container-compatible-range<value_type> R > flat_map( std::from_range_t fr, R&& rg ) |
(17) | (C++23 起) |
template< container-compatible-range<value_type> R, class Allocator > flat_map( std::from_range_t, R&& rg, const Allocator& alloc ); |
(18) | (C++23 起) |
template< container-compatible-range<value_type> R, class Allocator > flat_map( std::from_range_t, R&& rg, const key_compare& comp, |
(19) | (C++23 起) |
template< class InputIter > flat_map( std::sorted_unique_t s, InputIter first, InputIter last, |
(20) | (C++23 起) |
template< class InputIter, class Allocator > flat_map( std::sorted_unique_t s, InputIter first, InputIter last, |
(21) | (C++23 起) |
template< class InputIter, class Allocator > flat_map( std::sorted_unique_t s, InputIter first, InputIter last, |
(22) | (C++23 起) |
flat_map( std::initializer_list<value_type> init, const key_compare& comp = key_compare() ) |
(23) | (C++23 起) |
template< class Allocator > flat_map( std::initializer_list<value_type> init, const key_compare& comp, |
(24) | (C++23 起) |
template< class Allocator > flat_map( std::initializer_list<value_type> init, const Allocator& alloc ); |
(25) | (C++23 起) |
flat_map( std::sorted_unique_t s, std::initializer_list<value_type> init, const key_compare& comp = key_compare() ) |
(26) | (C++23 起) |
template< class Allocator > flat_map( std::sorted_unique_t s, std::initializer_list<value_type> init, |
(27) | (C++23 起) |
template< class Allocator > flat_map( std::sorted_unique_t s, std::initializer_list<value_type> init, |
(28) | (C++23 起) |
構造新的容器介面卡,可使用各種資料來源,並可選擇使用使用者提供的比較函式物件 comp 和/或分配器 alloc。
c.keys
,使用 std::move(mapped_cont) 初始化 c.values
,並使用 comp 初始化 compare
。然後,根據 value_comp() 對底層範圍 [
begin(),
end())
進行排序。最後,刪除重複元素,如同執行:auto zv = views::zip(c.keys, c.values);
auto it = ranges::unique(zv, key_equiv(compare)).begin();
auto dist = distance(zv.begin(), it);
c.keys.erase(c.keys.begin() + dist, c.keys.end());
c.values.erase(c.values.begin() + dist, c.values.end());.
[
first,
last)
的內容構造容器介面卡,等價於 insert(first, last);。c
,如同執行 insert_range(std::forward<R>(rg));。[
first,
last)
的內容構造底層容器,如同執行 insert(first, last)。對於過載 (13-15,20-22) 的注意事項:如果 [
first,
last)
不是有效範圍,則行為未定義。
對於過載 (4-6,13-19,23-25) 的注意事項:如果範圍中的多個元素的鍵比較相等,則插入哪個元素是未指定的(待解決 LWG2844)。
目錄 |
[編輯] 分配器使用說明
建構函式 (2,3,5,6,8,9,11,12,14,15,17,19,21,22,24,25,27,28) 等效於相應的非分配器建構函式,不同之處在於底層容器 c.keys
和 c.values
使用使用分配器構造。這些過載僅當 std::uses_allocator_v<container_type, Allocator> 為 true 時才參與過載決議。
[編輯] 引數
key_cont | - | 用作初始化底層鍵容器的源容器 |
mapped_cont | - | 用作初始化底層值容器的源容器 |
其他 | - | 另一個 flat_map ,用作初始化底層容器元素的源 |
alloc | - | 用於底層容器所有記憶體分配的分配器 |
comp | - | 一個用於所有鍵比較的函式物件 |
first, last | - | 定義要複製的元素的源 範圍 的迭代器對 |
init | - | 初始化列表,用於初始化底層容器的元素 |
rg | - | 容器兼容範圍(即,其元素可轉換為 value_type 的 input_range ),用作初始化底層容器的源 |
fr | - | 一個消歧標籤,指示包含的成員應進行範圍構造 |
s | - | 消歧標籤,指示輸入序列相對於 value_comp() 已排序且所有元素唯一 |
型別要求 | ||
-InputIt 必須滿足 LegacyInputIterator 的要求。 | ||
-Compare 必須滿足 Compare 的要求。 | ||
-Allocator 必須滿足 Allocator 的要求。 |
[編輯] 複雜度
[
first,
last)
相對於 value_comp() 已排序,則複雜度為 N 的線性時間,否則為 𝓞(N·log(N)),其中 N 是此呼叫前 key_cont.size() 的值。[
first,
last)
的大小呈線性關係。[編輯] 異常
呼叫 Allocator::allocate
可能會丟擲異常。
[編輯] 注意
在容器移動構造(過載 (3))之後,指向 other
的引用、指標和迭代器(除了尾迭代器)仍然有效,但現在指向 *this 中的元素。當前的標準透過 [container.reqmts]/67 中的一攬子宣告提供此保證,並且透過 LWG issue 2321 正在考慮更直接的保證。
[編輯] 示例
本節不完整 原因:無示例 |
[編輯] 參閱
向容器介面卡賦值 (public member function) |