std::swap(std::flat_set)(3)

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

🌸 NAME 🌸

This is the std::swap(std::flat_set) page from the C++ Standard Libary manual, bestie.

std::swap(std::flat_set) - std::swap(std::flat_set) β€” yes, the NAME section is literally the same thing twice, and that's iconic. πŸ’…

✨ Synopsis ✨

Defined in header <flat_set>

friend void swap( std::flat_set& lhs, std::flat_set& rhs ) noexcept;

It's marked (since C++23), and it specializes the std::swap algorithm for std::flat_set. It swaps the contents of lhs and rhs, and calls lhs.swap(rhs). 🫢

πŸ’– Parameters πŸ’–

  • lhs, rhs β€” containers whose contents to swap. Two containers, one little swap moment. πŸŽ€

😭 Return value 😭

(none) β€” literally nothing comes back, bestie. No return value, just vibes. πŸ’€

πŸ”₯ Complexity πŸ”₯

Same as swapping the underlying container. That's the complexity, no extra lore. ✨

πŸŽ€ Example πŸŽ€

The example says // Run this code β€” so go run it:

#include <algorithm>
#include <iostream>
#include <flat_set>

int main()
{
    std::flat_set<int> alice{1, 2, 3};
    std::flat_set<int> bob{7, 8, 9, 10};

    auto print = [](const int& n) { std::cout << ' ' << n; };

    // Print state before swap
    std::cout << "Alice:";
    std::for_each(alice.begin(), alice.end(), print);
    std::cout << "\n" "Bob  :";
    std::for_each(bob.begin(), bob.end(), print);
    std::cout << '\n';

    std::cout << "-- SWAP\n";
    std::swap(alice, bob);

    // Print state after swap
    std::cout << "Alice:";
    std::for_each(alice.begin(), alice.end(), print);
    std::cout << "\n" "Bob  :";
    std::for_each(bob.begin(), bob.end(), print);
    std::cout << '\n';
}

🌈 Output 🌈

Alice: 1 2 3
Bob  : 7 8 9 10
-- SWAP
Alice: 7 8 9 10
Bob  : 1 2 3

πŸ‘‘ See also πŸ‘‘

  • swap β€” swaps the contents (public member function). Yep, that's the member-function bestie. πŸ’œ

Source/version/date sign-off: http://cppreference.com β€” 2024.06.10 β€” page std::swap(std::flat_set)(3). Byeee, go swap your flat_sets responsibly πŸ’–

πŸ“¦ where this page comes from