std::atomic::fetch_max(3)
π std::atomic::fetch_max(3)
okay bestie, buckle up β this one's a C++ Standard Library page (section 3, std::atomic::fetch_max), and honestly? it's giving "tiny function, big feelings." no cap. πΈ
β¨ NAME β¨
std::atomic::fetch_max β literally just std::atomic::fetch_max. that's the whole name. iconic minimalism, we love to see it. π
π¦ Synopsis π¦
so there are four overloads and they're all noexcept, all since C++26, and all have order defaulting to std::memory_order_seq_cst. here's the receipts, verbatim:
overloads (1) and (2) are member only of atomic<Integral> specializations:
(1) (since C++26)
T fetch_max( T arg, std::memory_order order =
std::memory_order_seq_cst ) noexcept;
(2) (since C++26)
T fetch_max( T arg, std::memory_order order =
std::memory_order_seq_cst ) volatile noexcept;
overloads (3) and (4) are a member only of the atomic<T*> partial specialization:
(3) (since C++26)
T* fetch_max( T* arg, std::memory_order order =
std::memory_order_seq_cst ) noexcept;
(4) (since C++26)
T* fetch_max( T* arg, std::memory_order order =
std::memory_order_seq_cst ) volatile noexcept;
β¨ what does it actually do? it atomically replaces the current value with the result of std::max of the value and arg. that's an atomic maximum operation, bestie. it's a read-modify-write operation, and memory is affected according to the value of order. π«Ά
π¨ okay so real talk on overloads 3 and 4 β if the pointers point to different complete objects (or subobjects thereof), pointer comparison does not establish a strict weak ordering. that's the "don't @ me" footnote of this whole page. π
β οΈ and this one matters: it is deprecated ifstd::atomic<T>::is_always_lock_freeisfalseand overload (2) or (4) participates in overload resolution.
π Parameters π
argβ the other argument ofstd::max. it's the one your value is getting compared against. πorderβ memory order constraints to enforce. it's the vibe check for your memory ordering, fr fr.
β Return value β
the value immediately preceding the effects of this function in the modification order of *this. so like, the old value. the before pic. the pre-slide-into-your-DMs value. π
π Notes π
there's a feature-test macro for this and yes i'm putting the whole thing down:
- Feature-test macro:
__cpp_lib_atomic_min_max - Value:
202403L - Std:
(C++26) - Feature: Atomic minimum/maximum
π Example π
π this section is incomplete. Reason: no example.
bestie they really said "imagine an example." we're manifesting one for the next update, i guess. π§
π Category π
- Todo no example
<div>π that's the whole page! no cap, we covered every overload, every parameter, the return value, the macro, the deprecation warning, and the tragically example-less Example section. slay. π</div>
love u, stay lock-free (or don't β apparently it's deprecated) π«Άβ¨ β this cutie pie came from http://cppreference.com, dated 2024.06.10, and its own footer literally says std::atomic::fetch_max(3). periodt. ππΈ
π¦ 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