std::flat_set<Key,Compare,KeyContainer>::extract
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Containers library
(C++17)
(C++11)
(C++26)
(C++26)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++23)
(C++23)
(C++20)
(C++23)
Tables
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.
Contents
[edit] Return value
std::move(c).
[edit] Complexity
Constant.
[edit] Example
Run this code
#include <cassert> #include <flat_set> #include <print> #include <type_traits> #include <utility> #include <vector> int main() { std::flat_set <int> set{1, 2, 3}; const auto size{set.size()}; auto c{std::move(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]