std::atomic...ax_explicit(3)

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

πŸ’… std::atomic_fetch_max, std::atomic_fetch_max_explicit πŸ’…

C++ Standard Libary Β· page std::atomic...ax_explicit(3) Β· okay bestie, we’re doing atomic max energy today ✨


πŸ’– NAME πŸ’–

std::atomic_fetch_max,std::atomic_fetch_max_explicit - std::atomic_fetch_max,std::atomic_fetch_max_explicit

That’s the whole name, no cap: two functions, one maxy atomic moment 🫢


✨ Synopsis ✨

Defined in header <atomic>:

Defined in header <atomic>
template< class T >

T atomic_fetch_max( std::atomic<T>* obj,
(1) (since C++26)

                    typename std::atomic<T>::value_type arg )
noexcept;
template< class T >

T atomic_fetch_max( volatile std::atomic<T>* obj,
(2) (since C++26)

                    typename std::atomic<T>::value_type arg )
noexcept;
template< class T >

T atomic_fetch_max_explicit( std::atomic<T>* obj,
                             typename std::atomic<T>::value_type
(3) (since C++26)
arg,

                             std::memory_order order ) noexcept;
template< class T >

T atomic_fetch_max_explicit( volatile std::atomic<T>* obj,
                             typename std::atomic<T>::value_type
(4) (since C++26)
arg,

                             std::memory_order order ) noexcept;

So here’s the vibe: it atomically replaces the value pointed to by obj with the result of std::max between the old value of obj and arg. Then it returns the value obj held previously. The operation is performed as if this was executed:

1,2) obj->fetch_max(arg)
3,4) obj->fetch_max(arg, order)
Bestie, warning time: if std::atomic<T> has no fetch_max member (this member is only provided for integral and pointer types except bool), the program is ill-formed. That’s a hard no, not a cute little oopsie 😭

πŸŽ€ Parameters πŸŽ€

  • obj β€” pointer to the atomic object to modify
  • arg β€” the value to std::max with the value stored in the atomic object
  • order β€” the memory synchronization ordering

🫢 Return value 🫢

The value immediately preceding the effects of this function in the modification order of *obj. Slay, that’s the return value πŸ’–


🧠 Notes 🧠

Feature-test macro tea β˜•:

  • __cpp_lib_atomic_min_max β€” value 202403L; Std (C++26); feature Atomic minimum/maximum

πŸ“ Example πŸ“

This section is incomplete.

Reason: no example.

It’s giving β€œplaceholder era,” bestie β€” no example yet πŸ™ˆ


πŸ‘€ See also πŸ‘€

  • fetch_max (C++26) β€” atomically performs std::max between the argument and the value of the atomic object and obtains the value held previously (public member function of std::atomic<T>)
  • atomic_fetch_min, atomic_fetch_min_explicit (C++26) β€” replaces the atomic object with the result of std::min with a non-atomic argument and obtains the previous value of the atomic (function template)

πŸ’€ Category πŸ’€

  • * Todo no example

okay bye bestie β€” this page’s source/version/date footer energy is http://cppreference.com, 2024.06.10, page std::atomic...ax_explicit(3) πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from