Implement P0074: Making owner_less more flexible
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@252905 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -5351,7 +5351,11 @@ weak_ptr<_Tp>::lock() const _NOEXCEPT
|
||||
return __r;
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 14
|
||||
template <class _Tp = void> struct owner_less;
|
||||
#else
|
||||
template <class _Tp> struct owner_less;
|
||||
#endif
|
||||
|
||||
template <class _Tp>
|
||||
struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> >
|
||||
@@ -5385,6 +5389,30 @@ struct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> >
|
||||
{return __x.owner_before(__y);}
|
||||
};
|
||||
|
||||
#if _LIBCPP_STD_VER > 14
|
||||
template <>
|
||||
struct _LIBCPP_TYPE_VIS_ONLY owner_less<void>
|
||||
{
|
||||
template <class _Tp, class _Up>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
|
||||
{return __x.owner_before(__y);}
|
||||
template <class _Tp, class _Up>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const
|
||||
{return __x.owner_before(__y);}
|
||||
template <class _Tp, class _Up>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
|
||||
{return __x.owner_before(__y);}
|
||||
template <class _Tp, class _Up>
|
||||
_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 _Tp>
|
||||
class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
|
||||
{
|
||||
|
@@ -30,9 +30,28 @@
|
||||
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
|
||||
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
|
||||
// };
|
||||
//
|
||||
// Added in C++17
|
||||
// template<> struct owner_less<void>
|
||||
// {
|
||||
// template<class T, class U>
|
||||
// bool operator()(shared_ptr<T> const&, shared_ptr<U> const&) const;
|
||||
// template<class T, class U>
|
||||
// bool operator()(shared_ptr<T> const&, weak_ptr<U> const&) const;
|
||||
// template<class T, class U>
|
||||
// bool operator()(weak_ptr<T> const&, shared_ptr<U> const&) const;
|
||||
// template<class T, class U>
|
||||
// bool operator()(weak_ptr<T> const&, weak_ptr<U> const&) const;
|
||||
//
|
||||
// typedef unspecified is_transparent;
|
||||
// };
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include <set>
|
||||
#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<int> sp1;
|
||||
std::shared_ptr<void> sp2;
|
||||
std::shared_ptr<long> sp3;
|
||||
std::weak_ptr<int> 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::shared_ptr<X>, std::owner_less<>> s;
|
||||
std::shared_ptr<void> vp;
|
||||
s.find(vp);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@@ -75,7 +75,7 @@
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0092R1.html">P0092R1</a></td><td>LWG</td><td>Polishing <chrono></td><td>Kona</td><td>Complete</td><td>3.8</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0007R1.html">P0007R1</a></td><td>LWG</td><td>Constant View: A proposal for a <tt>std::as_const</tt> helper function template.</td><td>Kona</td><td>In progress</td><td></td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0156R0.htm" >P0156R0</a></td><td>LWG</td><td>Variadic lock_guard(rev 3).</td><td>Kona</td><td></td><td></td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0074R0.html">P0074R0</a></td><td>LWG</td><td>Making <tt>std::owner_less</tt> more flexible</td><td>Kona</td><td></td><td></td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0074R0.html">P0074R0</a></td><td>LWG</td><td>Making <tt>std::owner_less</tt> more flexible</td><td>Kona</td><td>Complete</td><td>3.8</td></tr>
|
||||
<tr><td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/P0013R1.html">P0013R1</a></td><td>LWG</td><td>Logical type traits rev 2</td><td>Kona</td><td></td><td></td></tr>
|
||||
<!-- <tr><td></td><td></td><td></td><td></td><td></td><td></td></tr> -->
|
||||
</table>
|
||||
|
Reference in New Issue
Block a user