std::atomic::fetch_max(3)

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

πŸ’… 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 if std::atomic<T>::is_always_lock_free is false and overload (2) or (4) participates in overload resolution.

πŸŽ€ Parameters πŸŽ€

  • arg β€” the other argument of std::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