I'm trying to wrap a std::shared_ptr inside a std::atomic. A trivial example would be:
std::atomic<std::shared_ptr<int>> ptr{std::make_shared<int>(42)};
When compiling with clang++ -std=c++2a -stdlib=libc++ test.cc I get following error:
_Atomic cannot be applied to type 'std::__1::shared_ptr<int>' which is not trivially copyable
CppReference suggests that in C++20, std::atomic's constructor supports std::shared_ptr.
I wanted to try std::atomic_shared_ptr instead but couldn't find the appropriate header. Neither experimental/atomic nor atomic could find the class.
Is there a standard supported way to wrap std::shared_ptr in std::atomic in C++20?
Update
As @NathanOliver suggested, for now I can use the atomic_* function overloads without wrapping the shared_ptr in an atomic.