std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::flat_map
flat_map()
: flat_map(key_compare()) {}
|
(1) | (since C++23) |
flat_map( const flat_map& other );
|
(2) | (since C++23) |
flat_map( flat_map&& other );
|
(3) | (since C++23) |
explicit flat_map( const key_compare& comp )
: c(), compare(comp) {}
|
(4) | (since C++23) |
flat_map( key_container_type key_cont,
mapped_container_type mapped_cont,
const key_compare& comp = key_compare() );
|
(5) | (since C++23) |
flat_map( std::sorted_unique_t,
key_container_type key_cont,
mapped_container_type mapped_cont,
const key_compare& comp = key_compare() );
|
(6) | (since C++23) |
template< class InputIter >
flat_map( InputIter first, InputIter last,
const key_compare& comp = key_compare() )
: c(), compare(comp);
|
(7) | (since C++23) |
template< class InputIter >
flat_map( std::sorted_unique_t, InputIter first, InputIter last,
const key_compare& comp = key_compare() )
: c(), compare(comp);
|
(8) | (since C++23) |
template< container-compatible-range<value_type> R >
flat_map( std::from_range_t, R&& rg )
: flat_map(std::from_range, std::forward<R>(rg), key_compare()) {}
|
(9) | (since C++23) |
template< container-compatible-range<value_type> R >
flat_map( std::from_range_t, R&& rg, const key_compare& comp )
: flat_map(comp);
|
(10) | (since C++23) |
flat_map( std::initializer_list<value_type> init,
const key_compare& comp = key_compare() )
: flat_map(init.begin(), init.end(), comp) {}
|
(11) | (since C++23) |
flat_map( std::sorted_unique_t,
std::initializer_list<value_type> init,
const key_compare& comp = key_compare() )
: flat_map(std::sorted_unique,
init.begin(), init.end(), comp) {}
|
(12) | (since C++23) |
| Constructors with allocators |
||
template< class Allocator >
explicit flat_map( const Allocator& alloc );
|
(1A) | (since C++23) |
template< class Allocator >
flat_map( const flat_map& other, const Allocator& alloc );
|
(2A) | (since C++23) |
template< class Allocator >
flat_map( flat_map&& other, const Allocator& alloc );
|
(3A) | (since C++23) |
template< class Allocator >
flat_map( const key_compare& comp, const Allocator& alloc );
|
(4A) | (since C++23) |
template< class Allocator >
flat_map( const key_container_type& key_cont,
const mapped_container_type& mapped_cont,
const Allocator& alloc );
|
(5A) | (since C++23) |
template< class Allocator >
flat_map( const key_container_type& key_cont,
const mapped_container_type& mapped_cont,
const key_compare& comp, const Allocator& alloc );
|
(5B) | (since C++23) |
template< class Allocator >
flat_map( std::sorted_unique_t,
const key_container_type& key_cont,
const mapped_container_type& mapped_cont,
const Allocator& alloc );
|
(6A) | (since C++23) |
template< class Allocator >
flat_map( std::sorted_unique_t,
const key_container_type& key_cont,
const mapped_container_type& mapped_cont,
const key_compare& comp, const Allocator& alloc );
|
(6B) | (since C++23) |
template< class InputIter, class Allocator >
flat_map( InputIter first, InputIter last, const Allocator& alloc );
|
(7A) | (since C++23) |
template< class InputIter, class Allocator >
flat_map( InputIter first, InputIter last,
const key_compare& comp, const Allocator& alloc );
|
(7B) | (since C++23) |
template< class InputIter, class Allocator >
flat_map( std::sorted_unique_t, InputIter first, InputIter last,
const Allocator& alloc );
|
(8A) | (since C++23) |
template< class InputIter, class Allocator >
flat_map( std::sorted_unique_t, InputIter first, InputIter last,
const key_compare& comp, const Allocator& alloc );
|
(8B) | (since C++23) |
template< container-compatible-range<value_type> R, class Allocator >
flat_map( std::from_range_t, R&& rg, const Allocator& alloc );
|
(9A) | (since C++23) |
template< container-compatible-range<value_type> R, class Allocator >
flat_map( std::from_range_t, R&& rg, const key_compare& comp,
const Allocator& alloc );
|
(10A) | (since C++23) |
template< class Allocator >
flat_map( std::initializer_list<value_type> init,
const Allocator& alloc );
|
(11A) | (since C++23) |
template< class Allocator >
flat_map( std::initializer_list<value_type> init,
const key_compare& comp, const Allocator& alloc );
|
(11B) | (since C++23) |
template< class Allocator >
flat_map( std::sorted_unique_t,
std::initializer_list<value_type> init,
const Allocator& alloc );
|
(12A) | (since C++23) |
template< class Allocator >
flat_map( std::sorted_unique_t,
std::initializer_list<value_type> init,
const key_compare& comp, const Allocator& alloc );
|
(12B) | (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.other using move semantics.c.keys with std::move(key_cont), c.values with std::move(mapped_cont), and compare with comp.[begin(), end()) with respect to value_comp().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.key_cont is not sorted with respect to key_comp() or contains equal elements, the behavior is undefined.[first, last).[first, last) is not a valid range, the behavior is undefined.insert(first, last) after constructing an empty container adaptor.insert(std::sorted_unique, first, last) after constructing an empty container adaptor.[first, last) is not sorted with respect to value_comp() or contains equal elements, the behavior is undefined.rg.insert_range(std::forward<R>(rg)) after constructing an empty container adaptor.init.init is not sorted with respect to value_comp() or contains equal elements, the behavior is undefined.Constructors with allocators 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 both std::uses_allocator_v<key_container_type, Allocator> and std::uses_allocator_v<mapped_container_type, Allocator> are true.
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 | - | the pair of iterators defining the source range of elements to copy |
| init | - | an initializer list to initialize the elements of the underlying containers with |
| rg | - | a container compatible range |
| Type requirements | ||
-InputIt must meet the requirements of LegacyInputIterator.
| ||
-Compare must meet the requirements of Compare.
| ||
-Allocator must meet the requirements of Allocator.
| ||
Complexity
Unless otherwise specified, the complexity requirements on constructors with allocators are the same of those on the corresponding non-allocator constructors.
other.size().key_cont and mapped_cont are both sorted with respect to value_comp(), otherwise 𝓞(N·log(N)), where N is the value of key_cont.size() before this call.key_cont.size() before this call.[first, last) is sorted with respect to value_comp(), otherwise 𝓞(N·log(N)), where N is std::distance(first, last).std::distance(first, last).rg is sorted with respect to value_comp(), otherwise 𝓞(N·log(N)), where N is ranges::distance(rg).ranges::distance(rg).init is sorted with respect to value_comp(), otherwise 𝓞(N·log(N)), where N is init.size().init.size().Exceptions
Calls to Allocator::allocate may throw.
Notes
After container move construction (overload (3,3A)), references, pointers, and iterators that originally refer to elements in 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.
If multiple elements in the range have keys that compare equivalent, it is unspecified which element is inserted (pending LWG2844).
Example
| This section is incomplete Reason: no example |
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| P3567R2 | C++23 | the copy and move constructors were implicit and wrong | declared, with correct semantics |
See also
| assigns values to the container adaptor (public member function) |