Class atomic
contains atomic versions of many different variable types. However, it doesn\'t contain an atomic enum type. Is there a way to use atomic enums or
You can create an atomic enum like this:
#include <atomic>
enum Decision {stay,flee,dance};
std::atomic<Decision> emma_choice {stay}; // emma_choice is atomic
You can also do the same thing with enum classes:
#include <atomic>
enum class Decision {stay,flee,dance};
std::atomic<Decision> emma_choice {Decision::stay}; // emma_choice is atomic
The generic atomic
template can be used for all trivially copyable types, including enumerations. Whether or not it's lock-free is up to the implementation; hopefully it will be, if the underlying integer type is.