std::atomic::fetch_and(3)

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

πŸŽ€ NAME πŸŽ€

std::atomic::fetch_and β€” from the C++ Standard Libary, and yes bestie, this is the atomic bitwise-AND member you call when you need read-modify-write energy without the chaos. πŸ’…


🌸 Synopsis 🌸

          member only of atomic<Integral > specializations
          T fetch_and( T arg, std::memory_order order =
       (1) (since C++11)
                                  std::memory_order_seq_cst ) noexcept;
          T fetch_and( T arg, std::memory_order order =
                                  std::memory_order_seq_cst ) volatile
       (2) (since C++11)
          noexcept;

Okay so here’s the tea: this is a member only of atomic<Integral > specializations. It atomically replaces the current value with the result of bitwise AND of the value and arg. The operation is a read-modify-write operation. Memory is affected according to the value of order. ✨

⚠️ It is deprecated if std::atomic<T>::is_always_lock_free is false and overload (2) participates in overload resolution. (since C++20)

πŸ’– Parameters πŸ’–

  • arg β€” the other argument of bitwise AND.
  • order β€” memory order constraints to enforce.

✨ Return value ✨

The value immediately preceding the effects of this function in the modification order of *this.


πŸ¦‹ See also πŸ¦‹

  • atomic_fetch_and β€” replaces the atomic object with the result of bitwise AND with a non-atomic argument and obtains the previous value of the atomic. (C++11) (function template)
  • atomic_fetch_and_explicit β€” replaces the atomic object with the result of bitwise AND with a non-atomic argument and obtains the previous value of the atomic. (C++11) (function template)

Source/version and date, for the record: http://cppreference.com β€’ 2024.06.10. Byeee, go atomically AND your bits responsibly πŸ’œπŸ¦‹πŸŽ€

πŸ“¦ where this page comes from