[PATCH] libstdc++: Add smart ptr owner_equals and owner_hash structs and members for P1901R2
Jonathan Wakely
jwakely@redhat.com
Fri Jun 6 11:27:23 GMT 2025
On 23/05/25 17:55 +0000, Paul Keir wrote:
>This patch implements C++26 "Enabling the Use of weak_ptr as Keys in Unordered Associative Containers", as specified in P1901R2.
>
>I don't have write access.
>
>Signed-off-by: Paul Keir <paul.keir@uws.ac.uk>
>
>Tested on x86_64-linux.
>
>libstdc++-v3/ChangeLog:
>
> * include/bits/shared_ptr.h: Added owner_equal and owner_hash members to shared_ptr and weak_ptr
> * include/bits/shared_ptr_base.h: Added owner_equal and owner_hash structs
> * testsuite/20_util/owner_equal/cmp.cc: New test.
> * testsuite/20_util/owner_equal/noexcept.cc: New test.
> * testsuite/20_util/owner_hash/cmp.cc: New test.
> * testsuite/20_util/owner_hash/noexcept.cc: New test.
> * testsuite/20_util/shared_ptr/observers/owner_equal.cc: New test.
> * testsuite/20_util/shared_ptr/observers/owner_hash.cc: New test.
> * testsuite/20_util/weak_ptr/observers/owner_equal.cc: New test.
> * testsuite/20_util/weak_ptr/observers/owner_hash.cc: New test.
>
>---
>
> libstdc++-v3/include/bits/shared_ptr.h | 57 ++++++++++
> libstdc++-v3/include/bits/shared_ptr_base.h | 40 +++++++
> libstdc++-v3/testsuite/20_util/owner_equal/cmp.cc | 122 +++++++++++++++++++++
> .../testsuite/20_util/owner_equal/noexcept.cc | 39 +++++++
> libstdc++-v3/testsuite/20_util/owner_hash/cmp.cc | 104 ++++++++++++++++++
> .../testsuite/20_util/owner_hash/noexcept.cc | 31 ++++++
> .../20_util/shared_ptr/observers/owner_equal.cc | 93 ++++++++++++++++
> .../20_util/shared_ptr/observers/owner_hash.cc | 90 +++++++++++++++
> .../20_util/weak_ptr/observers/owner_equal.cc | 71 ++++++++++++
> .../20_util/weak_ptr/observers/owner_hash.cc | 69 ++++++++++++
> 10 files changed, 716 insertions(+)
>
>diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h
>index a196a0f1212..9f25f6ccc23 100644
>--- a/libstdc++-v3/include/bits/shared_ptr.h
>+++ b/libstdc++-v3/include/bits/shared_ptr.h
>@@ -909,6 +909,63 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> : public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
> { };
>
>+#if __cplusplus > 202302L
All these preprocessor checks should now use the new macro you've
defined in bits/version.h
#ifdef __glibcxx_smart_ptr_owner_equality // >= C++26
(the __glibcxx_smart_ptr_owner_equality macro is the internal one
that's always defined after including bits/version.h, whereas the
__cpp_lib_xxx one will only be defined by <memory> and <version>).
Apart from that, the current diff at
https://github.com/gcc-mirror/gcc/compare/97e8cd9...pkeir:gcc:4f699d8
looks good for trunk.
If you can change those #if checks and send a new patch to the list,
I'll get it pushed to trunk.
Thanks!
More information about the Libstdc++
mailing list