diff --git a/include/memory b/include/memory index a162eafe..bd616726 100644 --- a/include/memory +++ b/include/memory @@ -5351,7 +5351,11 @@ weak_ptr<_Tp>::lock() const _NOEXCEPT return __r; } +#if _LIBCPP_STD_VER > 14 +template struct owner_less; +#else template struct owner_less; +#endif template struct _LIBCPP_TYPE_VIS_ONLY owner_less > @@ -5385,6 +5389,30 @@ struct _LIBCPP_TYPE_VIS_ONLY owner_less > {return __x.owner_before(__y);} }; +#if _LIBCPP_STD_VER > 14 +template <> +struct _LIBCPP_TYPE_VIS_ONLY owner_less +{ + template + _LIBCPP_INLINE_VISIBILITY + bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const + {return __x.owner_before(__y);} + template + _LIBCPP_INLINE_VISIBILITY + bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const + {return __x.owner_before(__y);} + template + _LIBCPP_INLINE_VISIBILITY + bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const + {return __x.owner_before(__y);} + template + _LIBCPP_INLINE_VISIBILITY + bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const + {return __x.owner_before(__y);} + typedef void is_transparent; +}; +#endif + template class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this { diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp index d091ae99..bf1719c6 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp @@ -30,9 +30,28 @@ // bool operator()(shared_ptr const&, weak_ptr const&) const; // bool operator()(weak_ptr const&, shared_ptr const&) const; // }; +// +// Added in C++17 +// template<> struct owner_less +// { +// template +// bool operator()(shared_ptr const&, shared_ptr const&) const; +// template +// bool operator()(shared_ptr const&, weak_ptr const&) const; +// template +// bool operator()(weak_ptr const&, shared_ptr const&) const; +// template +// bool operator()(weak_ptr const&, weak_ptr const&) const; +// +// typedef unspecified is_transparent; +// }; #include #include +#include +#include "test_macros.h" + +struct X {}; int main() { @@ -79,4 +98,25 @@ int main() assert(cs(w1, p3) || cs(w3, p1)); assert(cs(w3, p1) == cs(w3, p2)); } +#if TEST_STD_VER > 14 + { + std::shared_ptr sp1; + std::shared_ptr sp2; + std::shared_ptr sp3; + std::weak_ptr wp1; + + std::owner_less<> cmp; + cmp(sp1, sp2); + cmp(sp1, wp1); + cmp(sp1, sp3); + cmp(wp1, sp1); + cmp(wp1, wp1); + } + { + // test heterogeneous lookups + std::set, std::owner_less<>> s; + std::shared_ptr vp; + s.find(vp); + } +#endif } diff --git a/www/cxx1z_status.html b/www/cxx1z_status.html index be3d5911..9090af4b 100644 --- a/www/cxx1z_status.html +++ b/www/cxx1z_status.html @@ -75,7 +75,7 @@ P0092R1LWGPolishing <chrono>KonaComplete3.8 P0007R1LWGConstant View: A proposal for a std::as_const helper function template.KonaIn progress P0156R0LWGVariadic lock_guard(rev 3).Kona - P0074R0LWGMaking std::owner_less more flexibleKona + P0074R0LWGMaking std::owner_less more flexibleKonaComplete3.8 P0013R1LWGLogical type traits rev 2Kona