Namespaces
Variants
Views
Actions

std::flat_set<Key,Compare,KeyContainer>::extract

From cppreference.com
< cpp‎ | container‎ | flat set
 
 
 
 
container_type extract() &&;
(since C++23)

Extracts adapted container. *this is emptied, even if an exception is thrown. Equivalent to return std::move(c);.

Contents

[edit] Parameters

(none)

[edit] Return value

std::move(c), i.e. the underlying container.

[edit] Complexity

Constant.

[edit] Example

#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]

[edit] See also

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