admin管理员组文章数量:1416625
Prior to C++20 a std::shared_ptr<T>
could be accessed without synchronization via its methods, or atomically using std::atomic_... functions.
In C++20, these functions are deprecated, and instead one must use the partial template specialization of std::atomic
for std::shared_ptr<T>
.
At the same time std::atomic_ref
class template does not seem to have partial specialization for std::shared_ptr<T>
, and std::atomic_ref<std::shared_ptr<T>>
fails to compile with the error:
atomic_ref<T> requires T to be trivially copyable
Does it mean that one cannot use one std::shared_ptr<T>
-like object in C++20 both atomically and without synchronization (in the places where it is safe)?
And the usage of only atomic operations seems too ineffective where they can be avoided, because any atomic load access returns a copy of shared pointer with appropriate increase of use count in the control block.
本文标签: cWhy is stdatomicrefltstdsharedptrltTgtgt unavailableStack Overflow
版权声明:本文标题:c++ - Why is std::atomic_ref<std::shared_ptr<T>> unavailable? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745256676a2650144.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论