You cannot do anything like this during preprocessing, because this definition requires semantic information about types and their names that are not available during preprocessing.
A template trait of type is_atomic<T> must be provided by the implementation, but is not available even in C ++ 11. The utility will be very limited, because on platforms that support threads in general, it is rather unusual to have types that are atoms in themselves.
In addition, it may even be impossible to determine this only by type, since some types have different atomicity properties depending on their alignment from memory (without the alignment requirement for atomicity, which is mandatory for the type).
Instead, you should use the provided implementation of std::atomic<T> , which should provide the most efficient implementation for atomic operations (with given memory restrictions) available on this platform.
Using platform-specific memory restrictions or atomic access instructions, such implementations can be locked without atomic types, even if the underlying memory model provides atomicity for a non- bare type.
You can use std::atomic<T>::is_lockfree() to determine if such an implementation should use locks under the hood.
source share