Search⌘ K
AI Features

Specializations of std::atomic_ref

Explore how to specialize std::atomic_ref with user-defined types, pointers, and arithmetic types to enhance thread safety. Understand atomic operations, memory ordering, and how atomic_ref supports various data types in C++20 concurrency features.

You can specialize std::atomic_ref for user-defined types, use partial specializations for pointer types, or full specializations for arithmetic types such as integral or floating-point types.

Primary template

The primary template std::atomic_ref can be instantiated with a TriviallyCopyable type T as:

struct Counters { 
    int a;
    int b; 
};
Counter counter;
std::atomic_ref<Counters> cnt(counter);

Partial specializations for pointer types

The standard provides partial specializations for a pointer type: std::atomic_ref<T*>.

Specializations for arithmetic types

The standard provides ...