std::flat_set::replace(3)
β¨ std::flat_set::replace(3) β¨
Okay bestie, welcome to the std::flat_set::replace(3) manual page from the C++ Standard Libary β yes, that manual name is folded in right up top, no header-line copy-paste happening here. This is the glow-up for replacing that underlying container. π
πΈ NAME πΈ
std::flat_set::replace β the NAME line is literally std::flat_set::replace - std::flat_set::replace. It's giving "I contain myself," and honestly? Iconic. This page explains the member that replaces the underlying container for a std::flat_set.
π¦ Synopsis π¦
Here's the signature, no cap:
void replace( container_type&& cont );
Since C++23. β¨
So what does it do? It replaces the underlying container, c, and it's equivalent to:
c = std::move(cont);
Heads up, bestie: the elements ofcontmust be sorted with respect tocompare, andcontmust not contain equal elements. Otherwise, the behavior is undefined. This is the "do not skip the vibe check" part. π
π Parameters π
contβ a sorted container of typeKeyContainer, the contents of which will be moved into*this. π«Ά
β Return value β
(none) β nothing comes back, bestie. It's giving "I did the move and I'm not returning your texts." π
π Complexity π
Equals the complexity of std::move applied to the adapted container. No secret extra drama, no hidden plot twist β that's the whole complexity story. β¨
π Example π
// Run this code
#include <algorithm>
#include <cassert>
#include <flat_set>
#include <print>
#include <vector>
int main()
{
std::vector<int> keys{1, 2, 3};
assert(std::ranges::is_sorted(keys));
std::flat_set<int> set;
assert(set.empty());
set.replace(keys);
assert(set.size() == 3);
assert(keys.empty());
std::println("{}", set); // set.keys()
}
π Output π
[1, 2, 3]
Ate. Periodt. π
π See also π
extractβ extracts the underlying container (public member function). Go off,extract. π
Source/version/date sign-off: this iconic little page comes from http://cppreference.com, dated 2024.06.10, and it is the std::flat_set::replace(3) manual page. Mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms