Description
n4868/[atomic.ref.generic] says template parameter T of atomic_ref<T> should satisfy is_trivially_copyable_v.
Current atomic_ref<T> has static_assert for is_trivially_copyable_v<_Ty> && is_copy_constructible_v<_Ty> && is_move_constructible_v<_Ty> && is_copy_assignable_v<_Ty> && is_move_assignable_v<_Ty>, which is probably copy-pasted from atomic<T>.
This makes atomic_ref<const T> fail to compile since const T is not assignable, but I believe this is valid use case.
Test code
#include <atomic>
auto load_as_atomic(const std::atomic<int>& i)
{
return i.load();
}
auto load_as_atomic(const int& i)
{
// should compile
return std::atomic_ref(i).load();
}
int main() {}
This compiles with libstdc++ (Godbolt), but not with STL.
Possible Solution
Change static_assert to match standard wording.
Description
n4868/[atomic.ref.generic]says template parameterTofatomic_ref<T>should satisfyis_trivially_copyable_v.Current
atomic_ref<T>hasstatic_assertforis_trivially_copyable_v<_Ty> && is_copy_constructible_v<_Ty> && is_move_constructible_v<_Ty> && is_copy_assignable_v<_Ty> && is_move_assignable_v<_Ty>, which is probably copy-pasted fromatomic<T>.This makes
atomic_ref<const T>fail to compile sinceconst Tis not assignable, but I believe this is valid use case.Test code
This compiles with libstdc++ (Godbolt), but not with STL.
Possible Solution
Change
static_assertto match standard wording.