std::atomic::operator=(3)
πΈ 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 returnsdesired, 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
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms