std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::replace
Min standard notice:
Replaces the underlying containers c. Equivalent to:
# Declarations
void replace( key_container_type&& key_cont, mapped_container_type&& mapped_cont );
(since C++23)
# Parameters
keys_cont: a sorted keys container of type KeyContainer, the contents of which will be moved into *thismapped_cont: a container of mapped values of type MappedContainer, the contents of which will be moved into *this
# Return value
(none)
# Example
#include <algorithm>
#include <cassert>
#include <flat_map>
#include <print>
#include <vector>
int main()
{
std::vector<int> keys{1, 2, 3};
assert(std::ranges::is_sorted(keys));
std::vector<double> values{2.2, 3.3, 1.1};
assert(keys.size() == values.size());
std::flat_map<int, double> map;
assert(map.empty());
map.replace(keys, values);
assert(map.size() == 3);
assert(map.keys() == 3);
assert(map.values() == 3);
assert(keys.empty());
assert(values.empty());
std::println("{}", map);
}