Namespaces
Variants
Actions

std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>::extract

From cppreference.com
< cpp‎ | container‎ | flat map
 
C++
 
Containers library
 
std::flat_map
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.

Contents

[edit] Return value

std::move(c).

[edit] Complexity

Constant.

[edit] Example

#include <cassert>
#include <flat_map>
#include <print>
#include <type_traits>
#include <utility>
#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{std::move(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.values), std::vector<double>>);
 
    std::println("keys: {}", c.keys);
    std::println("values: {}", c.values);
}

Output:

keys: [1, 2, 3]
values: [1.1, 2.2, 3.3]

[edit] See also

replaces the underlying containers
(public member function) [edit]

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant