[c++0x] shared_ptr comparisons
Jonathan Wakely
jwakely.gcc@gmail.com
Sun Oct 26 12:59:00 GMT 2008
Update std::shared_ptr with the changes from n2637, such that
operator< compares the stored pointers not the addresses of the
control blocks.
I also took Chris's suggestion to use deleted functions in
_Sp_counted_ptr and I fixed the std::swap overloads for
shared/weak_ptr (which are needed in addition to the
__shared/__weak_ptr overloads in case users take the function's
address.)
Tested x86_64-unknown-linux-gnu. OK for mainline? I know we're late in
stage 3 but this only touches experimental C++0x stuff, and n2637
makes significant changes, so IMHO it would be good for both GCC and
C++0x if 4.4 implements the new ordering semantics.
N.B. the 20.8.13... section numbers are already wrong, because CD1 has
different numbering to n2798 ... ship happens.
Jonathan
* include/bits/shared_ptr.h: Update comparisons to match WP.
(_Sp_counted_ptr): Make copy and assignment members deleted.
(_Sp_counted_deleter): Remove private copy and assignment members.
(__shared_count::_M_less,__weak_count::_M_less,operator<): Replace
friend operator< with overloaded _M_less member functions to allow
comparison with either shared_count or weak_count.
(__shared_ptr::_M_less,__weak_ptr::_M_less): Replace with...
(__shared_ptr::owner_before,__weak_ptr::owner_before): New overloads
for ownership-based ordering.
(operator<(__shared_ptr,__shared_ptr)): Compare stored pointers,
make non-friend.
(operator==(__shared_ptr,__shared_ptr)): Make non-friend.
(operator!=(__shared_ptr,__shared_ptr)): Likewise.
(less<__shared_ptr<>>,less<shared_ptr<>>,_Sp_less): Explicitly call
pointer specialization.
(__weak_ptr::operator<,weak_ptr::operator<=,weak_ptr::operator>,
weak_ptr::operator>=): Remove operator< and delete all comparisons.
(_Sp_owner_less,owner_less): Predicate for ownership-based ordering.
(operator<(shared_ptr,shared_ptr): Overload for derived shared_ptr.
(operator==(shared_ptr,shared_ptr): Likewise.
(operator!=(shared_ptr,shared_ptr): Likewise.
(swap(shared_ptr,shared_ptr)): Fix parameter types.
(swap(weak_ptr,weak_ptr)): Add missing overload.
* testsuite/20_util/owner_less/cmp.cc: New.
* testsuite/20_util/shared_ptr/comparison/cmp.cc: Test other ops.
* testsuite/20_util/shared_ptr/comparison/less.cc: New.
* testsuite/20_util/shared_ptr/observers/owner_before.cc: New.
* testsuite/20_util/weak_ptr/observers/owner_before.cc: New.
* testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: New.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sp-20081026.patch
Type: text/x-patch
Size: 25876 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20081026/71b4d8e4/attachment.bin>
More information about the Libstdc++
mailing list