You can't do anything like this at preprocessing time, because that determination requires semantic information about types and their names, which are not available during preprocessing.
A templated is_atomic<T>
type trait would have to be provided by the implementation, but isn't available even in C++11. It utility would be very limited, because on platforms that support threads at all, it is rather unusual to have types that are atomic by themselves.
Additionally it may not even be possible to determine this from type alone, as some types have different atomicity properties depending on their memory alignment (without making the alignment requirements for atomicity mandatory for the type).
Instead you should use the implementation provided std::atomic<T>
, which ought to provide the most efficient implementation for atomic operations (with given memory constraints) available on a given platform.
By using platform-specific memory fence or atomic access instructions such implementations may be able to provide lock-free atomic types even if the underlying memory model provides atomicity for no 'naked' native type.
You can use std::atomic<T>::is_lockfree()
to determine whether such an implementation needs to use locks under the hood.