std::atomic_ref::fetch_add(3)

๐Ÿ“ฆ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

๐ŸŽ€ std::atomic_ref::fetch_add โ€” C++ Standard Libary, section 3 ๐Ÿ’…

๐ŸŒธ NAME ๐ŸŒธ

std::atomic_ref::fetch_add โ€” std::atomic_ref::fetch_add

Yes bestie, the name is literally the same on both sides. Itโ€™s giving mirror selfie energy ๐Ÿ’–.


โœจ Synopsis โœจ

okay so hereโ€™s the signature situation, and every line matters:

          member only of atomic_ref<Integral> and atomic_ref<Floating>
          template specializations
          T fetch_add( T arg,
                       std::memory_order order = std::memory_order_seq_cst )
       (1) (since C++20)
          const noexcept;
          member only of atomic_ref<T*> template specialization
          T* fetch_add( std::ptrdiff_t arg,
                        std::memory_order order = std::memory_order_seq_cst
       (2) (since C++20)
          ) const noexcept;

No cap: overload (1) is only for the atomic_ref<Integral> and atomic_ref<Floating> specializations, and overload (2) is only for the atomic_ref<T*> specialization. Both are (since C++20) and both are const noexcept era. Periodt โœจ.


๐Ÿงฎ Parameters ๐Ÿงฎ

  • arg โ€” the other argument of arithmetic addition. Itโ€™s the little number/pointer-ish bestie getting added in ๐Ÿซถ.
  • order โ€” memory order constraints to enforce. This is the vibe check for memory ordering ๐Ÿ’….

๐Ÿ’– Return value ๐Ÿ’–

The value of the referenced object, immediately preceding the effects of this function. Like, the old value right before the add did its main character thing ๐Ÿ’–.


๐Ÿงช Example ๐Ÿงช

This section is incomplete ๐Ÿ˜ญ.

Reason: no example.

bestie, the manpage really said โ€œno exampleโ€ and dipped ๐Ÿ™ˆ.

๐Ÿ—‚๏ธ Category ๐Ÿ—‚๏ธ

  • Todo no example

okay so what does this function actually do? It atomically replaces the current value of the referenced object with the result of arithmetic addition of the value and arg. This operation is a read-modify-write operation, no cap ๐Ÿ”ฅ. Memory is affected according to the value of order โœจ.

For signed integral types, arithmetic is defined to use twoโ€™s complement representation. There are no undefined results. Slay, no undefined-result jumpscare here ๐Ÿ’€.

For floating-point types, the floating-point environment in effect may be different from the calling thread's floating-point environment. The operation need not be conform to the corresponding std::numeric_limits traits but is encouraged to do so. If the result is not a representable value for its type, the result is unspecified but the operation otherwise has no undefined behavior ๐Ÿซถ.

For T* types, the result may be an undefined address, but the operation otherwise has no undefined behavior. The program is ill-formed if T is not an object type. Thatโ€™s the serious caveat, bestie โ€” do not skip it ๐Ÿ’….


okay bye bestie, this page came from http://cppreference.com, dated 2024.06.10, and itโ€™s the std::atomic_ref::fetch_add(3) page ๐Ÿ’œ๐Ÿซถโœจ

๐Ÿ“ฆ where this page comes from