Why is std::shared_ptr::unique() deprecated?

后端 未结 3 1332
误落风尘
误落风尘 2021-02-03 20:42

What is the technical problem with std::shared_ptr::unique() that is the reason for its deprecation in C++17?

According to cppreference.com, std::shar

3条回答
  •  伪装坚强ぢ
    2021-02-03 21:09

    For your viewing pleasure: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0488r0.pdf

    This document contains all NB (National Body) comments for the Issaquah meeting. CA 14 reads:

    The removal of the "debug only" restriction for use_count() and unique() in shared_ptr introduced a bug: in order for unique() to produce a useful and reliable value, it needs a synchronize clause to ensure that prior accesses through another reference are visible to the successful caller of unique(). Many current implementations use a relaxed load, and do not provide this guarantee, since it's not stated in the Standard. For debug/hint usage that was OK. Without it the specification is unclear and misleading.

提交回复
热议问题