std::flat_set::extract(3)

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

🌸 NAME 🌸

std::flat_set::extract - std::flat_set::extract

okay so bestie, welcome to std::flat_set::extract(3) from the C++ Standard Libary page β€” yes, that’s the manual name, and we’re about to get into the member function that literally extracts the adapted container. iconic behavior only. πŸ’…

✨ Synopsis ✨

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

Extracts adapted container c. Equivalent to return std::move(c);.

After this operation *this is empty, even if an exception is thrown. fr fr, that’s the rule β€” exception or no exception, *this ends up empty. 🫢

πŸŽ€ Parameters πŸŽ€

(none) β€” zero parameters, bestie. not a single one. πŸ“

πŸ’– Return value πŸ’–

std::move(c). that’s the whole return vibe. ✨

πŸ¦‹ Complexity πŸ¦‹

Constant. no extra drama, no cap. πŸ’€

🌈 Example 🌈

// Run this code

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

int main()
{
    std::flat_set<int> set{1, 2, 3};
    const auto size = set.size();

    auto c = set.extract();
    assert(c.size() == size);
    assert(set.empty());
    assert(set.keys().empty());
    assert(set.values().empty());

    // The default keys container is std::vector:
    static_assert(std::is_same_v<decltype(c), std::vector<int>>);

    std::println("{}", c);
}

🌟 Output 🌟

[1, 2, 3]

πŸ‘‘ See also πŸ‘‘

  • replace β€” replaces the underlying container (public member function)

bye bestie 🫢 this page’s source/version is http://cppreference.com, dated 2024.06.10, and the footer tag is std::flat_set::extract(3). mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from