std::flat_map::extract(3)
π std::flat_map::extract(3) β C++ Standard Libary π
okay so bestie, welcome to the std::flat_map::extract page β manual name is C++ Standard Libary (yes, that spelling is on the page, iykyk) and we are about to get into it. β¨
πΈ NAME πΈ
std::flat_map::extractβstd::flat_map::extract
periodt. the name section is doing its little name thing. π
β¨ Synopsis β¨
Signature:
containers extract() &&;
(since C++23) π¦
Extracts adapted containers c. Equivalent to return std::move(c);.
After this operation *this is empty, even if an exception is thrown. no cap β that is the whole deal, and it is giving βclean slate whether or not things go sideways.β π
π Parameters π
(none)
literally none. zero. nada. the parameter department is empty, and honestly? iconic. π«Ά
π Return value π
std::move(c).
that is the return value, bestie. slay. π
β‘ Complexity β‘
Constant.
fast. simple. no dramatic side quest. β
π¦ Example π¦
// Run this code
#include <cassert>
#include <flat_map>
#include <print>
#include <type_traits>
#include <vector>
int main()
{
std::flat_map<int, double> map{{1, 1.1}, {2, 2.2}, {3, 3.3}};
const auto size = map.size();
auto c = map.extract();
assert(c.keys.size() == size);
assert(c.values.size() == size);
assert(map.empty());
assert(map.keys().empty());
assert(map.values().empty());
// The default keys and values containers are std::vector:
static_assert(std::is_same_v<decltype(c.keys), std::vector<int>>);
static_assert(std::is_same_v<decltype(c.value), std::vector<int>>);
std::println("keys: {}", c.keys);
std::println("values: {}", c.values);
}
π Output π
keys: [1, 2, 3]
values: [1.1, 2.2, 3.3]
π See also π
replaceβ replaces the underlying containers (public member function)
mwah π signing off with the deets: source/version is http://cppreference.com, date is 2024.06.10, and the page is std::flat_map::extract(3). stay iconic, bestie πβ¨
π¦ 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