std::flat_set::operator=(3)

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

πŸ’… std::flat_set::operator=(3) πŸ’…

okay bestie, welcome to the std::flat_set::operator= page from the C++ Standard Libary manual ✨ this one is all about assignment β€” copy, move, and initializer_list β€” and it's lowkey iconic πŸ’…

🏷️ NAME

std::flat_set::operator= β€” literally std::flat_set::operator=, no cap πŸ’–

✨ Synopsis ✨

flat_set& operator=( const flat_set& other );              (1) (since C++23)
                                                           (implicitly declared)
flat_set& operator=( flat_set&& other );                   (2) (since C++23)
                                                           (implicitly declared)
flat_set& operator=( std::initializer_list<key_type> ilist (3) (since C++23)
);

It replaces the contents of the container adaptor with the contents of the given argument.

  1. Copy assignment operator. Replaces the contents with a copy of the contents of other. Effectively calls c = other.c; comp = other.comp;.
  2. Move assignment operator. Replaces the contents with those of other using move semantics. Effectively calls c = std::move(other.c); comp = std::move(other.comp);.
  3. Replaces the contents with those identified by initializer list ilist.

πŸ’– Parameters πŸ’–

  • other β€” another container adaptor to be used as source 🫢
  • ilist β€” initializer list to be used as source ✨

🎁 Return value 🎁

*this β€” that's literally the return value, bestie. periodt πŸ’…

πŸŒ€ Complexity πŸŒ€

  • 1, 2) Equivalent to that of operator= of the underlying container.
  • 3) Linear in the size of *this and ilist.

🌸 Example 🌸

okay watch this β€” the example does copy assignment, then move assignment, then initializer-list assignment, and prints the whole glow-up 🌸

// Run this code

#include <flat_set>
#include <initializer_list>
#include <print>

int main()
{
    std::flat_set<int> x{1, 2, 3}, y, z;
    const auto w = {4, 5, 6, 7};

    std::println("Initially:");
    std::println("x = {}", x);
    std::println("y = {}", y);
    std::println("z = {}", z);

    y = x; // overload (1)
    std::println("Copy assignment copies data from x to y:");
    std::println("x = {}", x);
    std::println("y = {}", y);

    z = std::move(x); // overload (2)
    std::println("Move assignment moves data from x to z, modifying both x and z:");
    std::println("x = {}", x);
    std::println("z = {}", z);

    z = w; // overload (3)
    std::println("Assignment of initializer_list w to z:");
    std::println("w = {}", w);
    std::println("z = {}", z);
}

πŸ“€ Output

Initially:
x = {1, 2, 3}
y = {}
z = {}
Copy assignment copies data from x to y:
x = {1, 2, 3}
y = {1, 2, 3}
Move assignment moves data from x to z, modifying both x and z:
x = {}
z = {1, 2, 3}
Assignment of initializer_list w to z:
w = {4, 5, 6, 7}
z = {4, 5, 6, 7}

πŸ‘€ See also πŸ‘€

  • constructor β€” constructs the flat_set (public member function)
  • replace β€” replaces the underlying container (public member function)

byeee bestie 🫢 this page came from http://cppreference.com, dated 2024.06.10, and it's literally std::flat_set::operator=(3) β€” stay slay, stay assigned πŸ’–βœ¨

πŸ“¦ where this page comes from