# std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>::extract

> C++ Atlas: `cppatlas.com/w/cpp/container/flat_multimap/extract` | Source: https://en.cppreference.com/w/cpp/container/flat_multimap/extract | Domain: Containers | Standards: C++23

Extracts adapted containers c. Equivalent to return std::move(c);.

## Official Specification Summary (cppreference)

```cpp
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.

### Parameters

(none)

### Return value

`std::move(c)`.

### Complexity

Constant.

### Example

```cpp
#include <cassert>
#include <flat_map>
#include <print>
#include <type_traits>
#include <vector>

int main()
{
    std::flat_multimap<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:

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

### See also

- [`replace`](https://en.cppreference.com/w/cpp/container/flat_multimap/replace): replaces the underlying containers (public member function)

---
Attribution: content from https://en.cppreference.com/w/cpp/container/flat_multimap/extract (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.