std::flat_m...set::replace(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… std::flat_m...set::replace(3) πŸ’…

okay so bestie, this page is from the C++ Standard Libary manual, and it's literally about swapping out the underlying container for a std::flat_multiset. lowkey iconic.


✨ NAME ✨

std::flat_multiset::replace β€” std::flat_multiset::replace

πŸ¦‹ Synopsis πŸ¦‹

void replace( container_type&& cont );  (since C++23)

She replaces the underlying container c, and it's equivalent to this move moment:

c = std::move(cont);

The elements of cont must be sorted with respect to compare. Otherwise, the behavior is undefined. 🫣🚨

🌸 Parameters 🌸

  • cont β€” a sorted container of type KeyContainer, the contents of which will be moved into *this

πŸ’– Return value πŸ’–

(none) β€” she gives nothing back, and honestly? mood. πŸ’…

πŸ”₯ Complexity πŸ”₯

Equals to complexity of std::move applied to adapted container.

🌈 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_multiset<int> set;
    assert(set.empty());

    set.replace(keys);
    assert(set.size() == 3);
    assert(keys.empty());

    std::println("{}", set); // set.keys()
}

πŸ–¨οΈ Output πŸ–¨οΈ

[1, 2, 3]

πŸ‘€ See also πŸ‘€

  • extract β€” extracts the underlying container (public member function)

mwah πŸ’‹ this little love letter came from http://cppreference.com, dated 2024.06.10, and the page is std::flat_m...set::replace(3) β€” periodt. πŸŽ€βœ¨

πŸ“¦ where this page comes from