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

FreeBSD Manual Pages

  
 
  

home | help
std::flat_m...map::replace(3) C++ Standard Libarystd::flat_m...map::replace(3)

NAME
       std::flat_multimap::replace - std::flat_multimap::replace

Synopsis
	  void replace(	key_container_type&& key_cont, mapped_container_type&&
       (since C++23)
	  mapped_cont );

	  Replaces the underlying containers c.	Equivalent to:

	c.keys = std::move(key_cont);
	c.values = std::move(mapped_cont);

	  The following	conditions must	be met:

	    * The expression key_cont.size() ==	mapped_cont.size() is true,
	    * The elements of key_cont are sorted with respect to compare.

	      Otherwise, the behavior is undefined.

Parameters
	  keys_cont   -	a sorted keys container	of type	KeyContainer, the con-
       tents of	which
			will be	moved into *this
	  mapped_cont  - a container of	mapped values of type MappedContainer,
       the contents of
			which will be moved into *this

Return value
	  (none)

Complexity
	  Equals to complexity of std::move applied to adapted containers.

Example
       // Run this code

	#include <algorithm>
	#include <cassert>
	#include <flat_map>
	#include <print>
	#include <vector>

	int main()
	{
	    std::vector<int> keys{1, 2,	3};
	    assert(std::ranges::is_sorted(keys));
	    std::vector<double>	values{2.2, 3.3, 1.1};
	    assert(keys.size() == values.size());

	    std::flat_multimap<int, double> map;
	    assert(map.empty());

	    map.replace(keys, values);
	    assert(map.size() == 3);
	    assert(map.keys() == 3);
	    assert(map.values()	== 3);
	    assert(keys.empty());
	    assert(values.empty());

	    std::println("{}", map);
	}

Output:
	{1: 2.2, 2: 3.3, 3: 1.1}

See also
	  extract extracts the underlying containers
		  (public member function)

http://cppreference.com		  2024.06.10	 std::flat_m...map::replace(3)

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

home | help