std::atomic_ref::fetch_min(3)

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

πŸ’… 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 of std::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 β€” value 202403L β€” 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