std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::flat_map
flat_map() : flat_map(key_compare()) { } |
(1) | (since C++23) |
template< class Allocator > flat_map( const flat_map&, const Allocator& alloc ); |
(2) | (since C++23) |
template< class Allocator > flat_map( flat_map&&, const Allocator& alloc ); |
(3) | (since C++23) |
flat_map( key_container_type key_cont, mapped_container_type mapped_cont, const key_compare& comp = key_compare() ); |
(4) | (since C++23) |
template< class Allocator > flat_map( const key_container_type& key_cont, |
(5) | (since C++23) |
template< class Allocator > flat_map( const key_container_type& key_cont, |
(6) | (since C++23) |
flat_map( std::sorted_unique_t, key_container_type key_cont, mapped_container_type mapped_cont, |
(7) | (since C++23) |
template< class Allocator > flat_map( std::sorted_unique_t, const key_container_type& key_cont, |
(8) | (since C++23) |
template< class Allocator > flat_map( std::sorted_unique_t, const key_container_type& key_cont, |
(9) | (since C++23) |
explicit flat_map( const key_compare& comp ) : c(), compare(comp) { } |
(10) | (since C++23) |
template< class Allocator > flat_map( const key_compare& comp, const Allocator& alloc ); |
(11) | (since C++23) |
template< class Allocator > explicit flat_map( const Allocator& alloc ); |
(12) | (since C++23) |
template< class InputIter > flat_map( InputIter first, InputIter last, |
(13) | (since C++23) |
template< class InputIter, class Allocator > flat_map( InputIter first, InputIter last, |
(14) | (since C++23) |
template< class InputIter, class Allocator > flat_map( InputIter first, InputIter last, const Allocator& alloc ); |
(15) | (since C++23) |
template< container-compatible-range<value_type> R > flat_map( std::from_range_t, R&& rg, const key_compare& comp ) |
(16) | (since C++23) |
template< container-compatible-range<value_type> R > flat_map( std::from_range_t fr, R&& rg ) |
(17) | (since C++23) |
template< container-compatible-range<value_type> R, class Allocator > flat_map( std::from_range_t, R&& rg, const Allocator& alloc ); |
(18) | (since C++23) |
template< container-compatible-range<value_type> R, class Allocator > flat_map( std::from_range_t, R&& rg, const key_compare& comp, |
(19) | (since C++23) |
template< class InputIter > flat_map( std::sorted_unique_t s, InputIter first, InputIter last, |
(20) | (since C++23) |
template< class InputIter, class Allocator > flat_map( std::sorted_unique_t s, InputIter first, InputIter last, |
(21) | (since C++23) |
template< class InputIter, class Allocator > flat_map( std::sorted_unique_t s, InputIter first, InputIter last, |
(22) | (since C++23) |
flat_map( std::initializer_list<value_type> init, const key_compare& comp = key_compare() ) |
(23) | (since C++23) |
template< class Allocator > flat_map( std::initializer_list<value_type> init, const key_compare& comp, |
(24) | (since C++23) |
template< class Allocator > flat_map( std::initializer_list<value_type> init, const Allocator& alloc ); |
(25) | (since C++23) |
flat_map( std::sorted_unique_t s, std::initializer_list<value_type> init, const key_compare& comp = key_compare() ) |
(26) | (since C++23) |
template< class Allocator > flat_map( std::sorted_unique_t s, std::initializer_list<value_type> init, |
(27) | (since C++23) |
template< class Allocator > flat_map( std::sorted_unique_t s, std::initializer_list<value_type> init, |
(28) | (since 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());.
c.keys
,使用 std::move(mapped_cont) 初始化 c.values
,并使用 comp 初始化 compare
。[
first,
last)
的内容构造容器适配器,等效于 insert(first, last);。c
。[
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
是通过 uses-allocator 构造构建的。仅当 std::uses_allocator_v<container_type, Allocator> 为 true 时,这些重载才参与重载解析。
[编辑] 参数
key_cont | - | 用作源以初始化底层键容器的容器 |
mapped_cont | - | 用作源以初始化底层值容器的容器 |
other | - | 另一个 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 考虑更直接的保证。
[编辑] 示例
本节尚不完整 原因:没有示例 |
[编辑] 参见
为容器适配器赋值 (公共成员函数) |