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) |
Constructs new container adaptor from a variety of data sources and optionally using user supplied comparison function object comp and/or allocator alloc.
c
with the copy of the contents of other.c and compare
with other.compare.
See allocator usage note below.c.keys
with std::move(key_cont), c.values
with std::move(mapped_cont), and compare
with comp. Then sorts the underlying range [
begin(),
end())
with respect to value_comp(). Finally, erases the duplicate elements as if by: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
with std::move(key_cont), c.values
with std::move(mapped_cont), and compare
with comp.[
first,
last)
, equivalent to insert(first, last);.c
with the contents of rg as if by insert_range(std::forward<R>(rg));.[
first,
last)
as if by insert(first, last).Note for overloads (13-15,20-22): If [
first,
last)
is not a valid range, the behavior is undefined.
Note for overloads (4-6,13-19,23-25): If multiple elements in the range have keys that compare equivalent, it is unspecified which element is inserted (pending LWG2844).
Contents |
[edit] Allocator usage note
The constructors (2,3,5,6,8,9,11,12,14,15,17,19,21,22,24,25,27,28) are equivalent to the corresponding non-allocator constructors except that the underlying containers c.keys
and c.values
are constructed with uses-allocator construction.
These overloads participate in overload resolution only if std::uses_allocator_v<container_type, Allocator> is true.
[edit] Parameters
key_cont | - | a container to be used as source to initialize the underlying keys container |
mapped_cont | - | a container to be used as source to initialize the underlying values container |
other | - | another flat_map to be used as source to initialize the elements of the underlying containers with
|
alloc | - | an allocator to use for all memory allocations of the underlying containers |
comp | - | a function object to be used for all comparisons of keys |
first, last | - | a range to copy the elements from |
init | - | an initializer list to initialize the elements of the underlying containers with |
rg | - | a container compatible range (that is, an input_range whose elements are convertible to value_type ) to be used as source to initialize the underlying containers
|
fr | - | a disambiguation tag that indicates that the contained member should be range constructed |
s | - | a disambiguation tag that indicates that the input sequence is sorted with respect to value_comp() and all its elements are unique |
Type requirements | ||
-InputIt must meet the requirements of LegacyInputIterator.
| ||
-Compare must meet the requirements of Compare.
| ||
-Allocator must meet the requirements of Allocator.
|
[edit] Complexity
[
first,
last)
is sorted with respect to value_comp(), otherwise 𝓞(N·log(N)), where N is the value of key_cont.size() before this call.[
first,
last)
.[edit] Exceptions
Calls to Allocator::allocate
may throw.
[edit] Notes
After container move construction (overload (3)), references, pointers, and iterators (other than the end iterator) to other
remain valid, but refer to elements that are now in *this. The current standard makes this guarantee via the blanket statement in [container.reqmts]/67, and a more direct guarantee is under consideration via LWG issue 2321.
[edit] Example
This section is incomplete Reason: no example |
[edit] See also
assigns values to the container adaptor (public member function) |