This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.
2434.shared_ptr::use_count()
is efficient
Section: 20.3.2.2.6 [util.smartptr.shared.obs] Status: C++17 Submitter: Stephan T. Lavavej Opened: 2014-10-01 Last modified: 2017-07-30
Priority: 0
View all other issues in [util.smartptr.shared.obs].
View all issues with C++17 status.
Discussion:
shared_ptr
and weak_ptr
have Notes that their use_count()
might be inefficient. This is an attempt to acknowledge reflinked implementations (which can be used by Loki smart pointers, for example). However, there aren't any shared_ptr
implementations that use reflinking, especially after C++11 recognized the existence of multithreading. Everyone uses atomic refcounts, so use_count()
is just an atomic load.
[Urbana 2014-11-07: Move to Ready]
Proposed resolution:
This wording is relative to N3936.
Change 20.3.2.2.6 [util.smartptr.shared.obs] p7-p10 as depicted:
long use_count() const noexcept;-7- Returns: the number of
-8- [Note:shared_ptr
objects,*this
included, that share ownership with*this
, or 0 when*this
is empty.use_count()
is not necessarily efficient. — end note]bool unique() const noexcept;-9- Returns:
-10- [Note:use_count() == 1
.unique()
may be faster thanuse_count()
. If you are usingunique()
to implement copy on write, do not rely on a specific value whenget() == 0
. — end note]
Change 20.3.2.3.6 [util.smartptr.weak.obs] p1-p4 as depicted:
long use_count() const noexcept;-1- Returns: 0 if
-2- [Note:*this
is empty; otherwise, the number ofshared_ptr
instances that share ownership with*this
.use_count()
is not necessarily efficient. — end note]bool expired() const noexcept;-3- Returns:
-4- [Note:use_count() == 0
.expired()
may be faster thanuse_count()
. — end note]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4