[libcxx] Add deduction guides for shared_ptr and weak_ptr
This patch adds deduction guides to <memory> to allow deducing
construction of shared_ptrs from unique_ptrs, and from weak_ptrs
and vice versa, as specified by C++17.
Differential Revision: https://reviews.llvm.org/D69603
Cr-Mirrored-From: https://chromium.googlesource.com/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 83564056d4b186c9fcf016cdbb388755009f7b5a
diff --git a/include/memory b/include/memory
index 729b8b5..29c5e98 100644
--- a/include/memory
+++ b/include/memory
@@ -450,6 +450,11 @@
template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
};
+template<class T>
+shared_ptr(weak_ptr<T>) -> shared_ptr<T>;
+template<class T, class D>
+shared_ptr(unique_ptr<T, D>) -> shared_ptr<T>;
+
// shared_ptr comparisons:
template<class T, class U>
bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
@@ -548,6 +553,9 @@
template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
};
+template<class T>
+weak_ptr(shared_ptr<T>) -> weak_ptr<T>;
+
// weak_ptr specialized algorithms:
template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
@@ -3965,6 +3973,12 @@
template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
};
+#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+template<class _Tp>
+shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>;
+template<class _Tp, class _Dp>
+shared_ptr(unique_ptr<_Tp, _Dp>) -> shared_ptr<_Tp>;
+#endif
template<class _Tp>
inline
@@ -4765,6 +4779,11 @@
template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
};
+#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
+template<class _Tp>
+weak_ptr(shared_ptr<_Tp>) -> weak_ptr<_Tp>;
+#endif
+
template<class _Tp>
inline
_LIBCPP_CONSTEXPR