Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::flat_map::extract(3)     C++ Standard Libary    std::flat_map::extract(3)

NAME
       std::flat_map::extract -	std::flat_map::extract

Synopsis
	  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
       // Run this code

	#include <cassert>
	#include <flat_map>
	#include <print>
	#include <type_traits>
	#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 = 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::vec-
       tor<int>>);

	    std::println("keys:	{}", c.keys);
	    std::println("values: {}", c.values);
	}

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

See also
	  replace replaces the underlying containers
		  (public member function)

http://cppreference.com		  2024.06.10	     std::flat_map::extract(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::flat_map::extract&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help