std::atomic::operator=(3)

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

🌸 NAME 🌸

std::atomic::operator= - std::atomic::operator= β€” okay so this is the std::atomic::operator= page from the C++ Standard Libary manual, and it's giving assignment operator but make it atomic energy. Bestie, this is the assignment operator for std::atomic types, and yes, there are four overloads. Buckle up. πŸ’…


✨ Synopsis ✨

T operator=( T desired ) noexcept;                    (1) (since C++11)
T operator=( T desired ) volatile noexcept;           (2) (since C++11)
atomic& operator=( const atomic& ) = delete;          (3) (since C++11)
atomic& operator=( const atomic& ) volatile = delete; (4) (since C++11)

Overloads (1) and (2) β€” these atomically assign desired to the atomic variable. Equivalent to store(desired). Since C++11, periodt. ✨

🚨 Deprecation tea: it is deprecated if std::atomic<T>::is_always_lock_free is false and β€” since C++20 β€” overload (2) participates in overload resolution. No cap, that's the exact caveat. 😭

Overloads (3) and (4) β€” atomic variables are not CopyAssignable. So these copy-assignment overloads are deleted, literally = delete, since C++11. πŸ™ˆ


πŸŽ€ Parameters πŸŽ€

  • desired β€” value to assign. That's it, that's the parameter. πŸ’–

🌈 Return value 🌈

  • (1), (2) β€” desired. Yes bestie, it returns desired, not a reference to the left-hand side. Plot twist below. 😭

πŸ¦‹ Notes πŸ¦‹

Unlike most assignment operators, the assignment operators for atomic types do not return a reference to their left-hand arguments. They return a copy of the stored value instead. The way that this is lowkey the main character detail of the whole page β€” do not forget it. πŸ‘‘


πŸ‘‘ See also πŸ‘‘

  • constructor β€” constructs an atomic object (public member function).

made with πŸ’– from source http://cppreference.com, version/date 2024.06.10, page std::atomic::operator=(3). Slay responsibly. 🫢

πŸ“¦ where this page comes from