std::flat_set<Key,Compare,KeyContainer>::replace
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
void replace( container_type&& cont );
 
 (since C++23) 
Replaces the underlying container c. Equivalent to:
c = std::move(cont);.
The elements of cont must be sorted with respect to compare, and cont must not contain equal elements. Otherwise, the behavior is undefined.
[edit] Parameters
 cont
 -
 a sorted container of type 
KeyContainer, the contents of which will be moved into *this
[edit] Return value
(none)
[edit] Complexity
Equals to complexity of std::move applied to adapted container.
[edit] Example
Run this code
#include <algorithm> #include <cassert> #include <flat_set> #include <print> #include <vector> int main() { std::vector <int> keys{1, 2, 3}; assert (std::ranges::is_sorted (keys)); std::flat_set <int> set; assert (set.empty()); set.replace(keys); assert (set.size() == 3); assert (keys.empty()); std::println ("{}", set); // set.keys() }
Output:
[1, 2, 3]