std::flat_m...map::extract(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… std::flat_multimap::extract πŸ’…

okay so bestie, this is the std::flat_m...map::extract(3) page from the C++ Standard Libary manual β€” and yes, β€œLibary” is literally spelled that way up top, we are not fixing the lore, we respect the lore. 🫢 It’s giving very niche C++23 container magic, and honestly? iconic.

✨ NAME ✨

std::flat_multimap::extract - std::flat_multimap::extract

✨ Synopsis ✨

containers extract() &&;  (since C++23)

It extracts adapted containers c. Equivalent to return std::move(c);.

After this operation *this is empty, even if an exception is thrown. Like, the emptiness is not canceled by drama β€” periodt. πŸ’…

🌸 Parameters 🌸

(none) β€” no parameters, not a single one, we love a low-maintenance icon. ✨

πŸ’– Return value πŸ’–

It returns std::move(c).

πŸ¦‹ Complexity πŸ¦‹

Constant. That’s the whole vibe: constant, no stress, no loops, just slay. πŸ”₯

πŸŽ€ Example πŸŽ€

The page even drops a lil // Run this code before the snippet:

#include <cassert>
#include <flat_map>
#include <print>
#include <type_traits>
#include <vector>

int main()
{
    std::flat_multimap<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). that’s the cross-reference, bestie, go get the container-swap tea 🍡

xoxo, your fave little reference page β€” source is http://cppreference.com, dated 2024.06.10, and the title again is std::flat_m...map::extract(3). bye bestie πŸ’–

πŸ“¦ where this page comes from