STD::ATOMIC(3)

πŸ’– std::atomic< _Tp > β€” the generic atomic type, primary class template πŸ’–

okay bestie so this is std::atomic< _Tp >(3), straight outta the Library Functions Manual, and it's genuinely one of the most iconic glow-ups in the whole C++ standard library. no cap. if you've ever had two threads fighting over the same variable like it's the last matcha in the fridge, this is the class template that ends the drama. 🫢


✨ NAME ✨

std::atomic< _Tp > β€” Generic atomic type, primary class template. that's the whole vibe. it's the primary one, the blueprint, the main character πŸ‘‘


🌈 SYNOPSIS 🌈

#include <atomic>

πŸŽ€ Public Types

  • using value_type β€” yeah it's just chillin' there, one type, doing its thing.

πŸ¦‹ Public Member Functions

okay this list is LONG and I am NOT skipping a single one, because every overload here is a baddie and they all earned their spot πŸ’…

  • constexpr atomic (_Tp __i) noexcept β€” build one of these, feed it your starting value __i, no exceptions, we don't do that here.
  • atomic (const atomic &)=delete β€” nope. copying is deleted. atoms don't get duplicated, that's the whole point, periodt. πŸ’€
  • bool compare_exchange_strong (_Tp &__e, _Tp __i, memory_order __m=memory_order_seq_cst) noexcept β€” the strong compare-and-swap. if the current value matches __e, swap in __i and say true; otherwise write the actual value back into __e and say false. default ordering memory_order_seq_cst.
  • bool compare_exchange_strong (_Tp &__e, _Tp __i, memory_order __m=memory_order_seq_cst) volatile noexcept β€” same energy, but volatile.
  • bool compare_exchange_strong (_Tp &__e, _Tp __i, memory_order __s, memory_order __f) noexcept β€” strong version where you get to pick two orderings: __s for success, __f for failure. so flexible ✨
  • bool compare_exchange_strong (_Tp &__e, _Tp __i, memory_order __s, memory_order __f) volatile noexcept β€” the volatile twin of the above.
  • bool compare_exchange_weak (_Tp &__e, _Tp __i, memory_order __m=memory_order_seq_cst) noexcept β€” the weak one. same deal, same default ordering, but it's allowed to fail even when the values match (spurious failure is real, that's just how it is on some hardware).
  • bool compare_exchange_weak (_Tp &__e, _Tp __i, memory_order __m=memory_order_seq_cst) volatile noexcept β€” weak, volatile, iconic.
  • bool compare_exchange_weak (_Tp &__e, _Tp __i, memory_order __s, memory_order __f) noexcept β€” weak + your choice of success ordering __s and failure ordering __f.
  • bool compare_exchange_weak (_Tp &__e, _Tp __i, memory_order __s, memory_order __f) volatile noexcept β€” and the volatile version of that one too. we contain multitudes.
  • _Tp exchange (_Tp __i, memory_order __m=memory_order_seq_cst) noexcept β€” drop in __i and hand back the old value. give and receive, that's the exchange. πŸ’ž
  • _Tp exchange (_Tp __i, memory_order __m=memory_order_seq_cst) volatile noexcept β€” exchange, but volatile.
  • bool is_lock_free () const noexcept β€” asks the question we all ask: is this thing actually lock-free, or is it secretly locking under the hood? const, no exceptions.
  • bool is_lock_free () const volatile noexcept β€” same question, const volatile flavour.
  • _Tp load (memory_order __m=memory_order_seq_cst) const noexcept β€” read the value out. default ordering memory_order_seq_cst, const, noexcept. πŸ“–
  • _Tp load (memory_order __m=memory_order_seq_cst) const volatile noexcept β€” load, but const volatile.
  • operator _Tp () const noexcept β€” surprise! it implicitly converts to _Tp, so you can just use it like a regular value. the versatility 😭
  • operator _Tp () const volatile noexcept β€” the const volatile conversion operator, obviously.
  • _Tp operator= (_Tp __i) noexcept β€” assign a plain _Tp into it, get the value back. noexcept, as always.
  • _Tp operator= (_Tp __i) volatile noexcept β€” the volatile assignment.
  • atomic & operator= (const atomic &) volatile =delete β€” copy-assignment? deleted. volatile flavour. NO copying, bestie, I said what I said.
  • atomic & operator= (const atomic &)=delete β€” and the non-volatile one is deleted too. both doors locked πŸ”’
  • void store (_Tp __i, memory_order __m=memory_order_seq_cst) noexcept β€” write __i in. default ordering memory_order_seq_cst, returns nothing, throws nothing. clean.
  • void store (_Tp __i, memory_order __m=memory_order_seq_cst) volatile noexcept β€” store, volatile edition.

πŸ‘‘ Detailed Description πŸ‘‘

template<typename _Tp>
    struct std::atomic< _Tp >
"Generic atomic type, primary class template."

that's the official blurb and honestly? it ate. this is the primary class template, the one all the specializations look up to.

🌸 Template Parameters

  • _Tp β€” Type to be made atomic, must be trivially copyable. lowkey the most important sentence on this page. if your type isn't trivially copyable, this template is NOT the one for you, and it will let you know. πŸ™ˆ

πŸ’œ Author

Generated automatically by Doxygen for libstdc++ from the source code. no human author to thank here, just the machine doing its little automated thing. πŸ€–βœ¨


and that's the page, bestie!! πŸŽ€ this one came to you from libstdc++, filed under std::atomic< _Tp >(3) β€” so next time you're in the terminal and you see that section-3 header, you'll know exactly who you're dealing with. go forth and atomically. πŸ’…πŸ¦‹β­

πŸ“¦ where this page comes from
  • arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
  • fedora 44: libstdc++-docs 16.0.1-0.10.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • fedora 44: libstdc++-docs 16.2.1-2.fc44
  • fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms