std::atomic_ref::fetch_min(3)
π std::atomic_ref::fetch_min(3)
okay bestie, welcome to the manual page for std::atomic_ref::fetch_min, straight out of the C++ Standard Library section of the docs π this one's a new-ish little icon, so let's get into it β¨
πΈ NAME
std::atomic_ref::fetch_min β literally std::atomic_ref::fetch_min, bestie, the name tells you the whole story π
β SYNOPSIS
so there's two flavors of this, and you only get one or the other depending on your specialization π
member only of atomic_ref<Integral > specializations
T fetch_min( T arg, std::memory_order order =
std::memory_order_seq_cst ) const
(1) (since C++26)
noexcept;
member only of atomic_ref<T*> partial specialization
T* fetch_min( T* arg, std::memory_order order =
std::memory_order_seq_cst ) const
(2) (since C++26)
noexcept;
ngl, both of these are noexcept and both are since C++26 β so if you're on an older standard, this is giving "not yet, babe" π
π DESCRIPTION
okay so the vibe here: it atomically replaces the current value of the referenced object with the result of std::min of the value and arg. that's it, that's the whole thing β it performs an atomic minimum operation π¦
and like, it's not just a read or just a write β it's a full read-modify-write operation. the memory is affected according to the value of order, so keep your eyes on that parameter, iykyk π
2) now for the pointer version β this is the part where you gotta be careful, bestie π«Ά if the pointers point to different complete objects (or subobjects thereof), then pointer comparison does not establish a strict weak ordering. so like, don't be out here comparing pointers to totally unrelated things and expecting a sensible answer, fr fr π
β¨ PARAMETERS
argβ the other argument ofstd::minπ (yes, that's really all it is)orderβ the memory order constraints to enforce, aka the rules of the game π₯
π RETURN VALUE
it hands you back the value that was immediately preceding the effects of this function in the modification order of *this π so like, the "before" picture, if the "before" picture were a value in a modification order. slay.
π§ NOTES
feature-test macro time, bestie β here's the one you're looking for π
__cpp_lib_atomic_min_maxβ value202403Lβ standard(C++26)β feature: Atomic minimum/maximum β
that's your "am I allowed to use this" check, periodt π
π EXAMPLE
This section is incomplete Reason: no example
not me finding a page with no example π the docs really said "figure it out yourself" π
π CATEGORY
- Todo no example
and that's the whole page, bestie!! π«Ά this gem came to you from http://cppreference.com, version 2024.06.10, dated 2024.06.10 β go forth and atomically minimum your way through C++26 πβ¨πΈ
π¦ 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