std::flat_map::extract(3)

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

πŸ’– 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