This answer has already been answered by this answer.
I asked this problem to come up with a map with a tuple containing std::atomic_flag , and adding explicit initialization easily adds a lot of complex code.
A workaround is to simply wrap it in another type, such as this one:
struct atomic_flag_ : public std::atomic_flag { atomic_flag_() : std::atomic_flag{ ATOMIC_FLAG_INIT } { } };
or without inheritance:
struct atomic_flag_ { std::atomic_flag flag{ ATOMIC_FLAG_INIT }; };
Now you do not need to worry about initialization (except for some special cases, such as static init fiasco).
source share