Namespaces
Variants

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

From zh.cppreference.net

container_type extract ( ) && ;
(自 C++23 起)

提取适配的容器 c 。等价于 return std :: move ( c ) ; 。

在此操作后, * this 将变为空,即使抛出异常也是如此。

目录

返回值

std :: move ( c ) 。

复杂度

常量。

示例

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

int main()
{
    std::flat_multiset<int> set{1, 2, 3};
    const auto size{set.size()};
    
    auto c{std::move(set).extract()};
    assert(c.size() == size);
    assert(set.empty());
    
    // The default keys container is std::vector:
    static_assert(std::is_same_v<decltype(c), std::vector<int>>);
    
    std::println("{}", c);
}

输出:

[1, 2, 3]

参见

替换底层容器
(公开成员函数)