std::atomic...:atomic_flag(3)

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

πŸŽ€ NAME πŸŽ€

okay so we're in the C++ Standard Libary manual (yes, that's the spelling in the header, no cap 🫢), and this page is std::atomic...:atomic_flag(3). The NAME line is literally:

std::atomic_flag::atomic_flag - std::atomic_flag::atomic_flag

yes bestie, same string twice β€” she's giving main character energy πŸ’… iconic behavior, honestly.


✨ Synopsis ✨

This constructor lives in header <atomic>, and here's the exact synopsis, copied with love:

          Defined in header <atomic>
          atomic_flag() noexcept = default;                   (since C++11)
                                                      (1)     (until C++20)
          constexpr atomic_flag() noexcept;                   (since C++20)
          atomic_flag( const atomic_flag& ) = delete;     (2) (since C++11)

This thing constructs a new std::atomic_flag. That's the whole vibe. Now the numbered tea:

  • 1) Trivial default constructor, initializes std::atomic_flag to unspecified state. (until C++20)
  • 1) Initializes std::atomic_flag to clear state. (since C++20)
  • 2) The copy constructor is deleted; std::atomic_flag is not copyable.

So like… if you were thinking about copying one, don't 😭 the copy constructor is literally = delete. She said not copyable and she meant it.

Also, std::atomic_flag can be value-initialized to clear state with the expression ATOMIC_FLAG_INIT. And for an atomic_flag with static storage duration, this guarantees static initialization: the flag can be used in constructors of static objects. That's a very specific little power move, and we respect it 🫑✨.


πŸ‘€ See also πŸ‘€

  • ATOMIC_FLAG_INIT β€” initializes an std::atomic_flag to false (C++11) (macro constant).

mwah πŸ’‹ source is http://cppreference.com, version/date 2024.06.10, page std::atomic...:atomic_flag(3) β€” go forth and flag your atomics, bestie πŸ’–πŸŒˆ

πŸ“¦ where this page comes from