summaryrefslogtreecommitdiffstats
path: root/contrib/libc++/include/memory
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libc++/include/memory')
-rw-r--r--contrib/libc++/include/memory1477
1 files changed, 1289 insertions, 188 deletions
diff --git a/contrib/libc++/include/memory b/contrib/libc++/include/memory
index 878dda8..aa24f96 100644
--- a/contrib/libc++/include/memory
+++ b/contrib/libc++/include/memory
@@ -596,22 +596,20 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
#include <iterator>
#include <__functional_base>
#include <iosfwd>
+#include <tuple>
+#include <cstring>
#if defined(_LIBCPP_NO_EXCEPTIONS)
#include <cassert>
#endif
+#include <__undef_min_max>
+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
-// allocator_arg_t
-
-struct _LIBCPP_VISIBLE allocator_arg_t { };
-
-extern const allocator_arg_t allocator_arg;
-
// addressof
template <class _Tp>
@@ -675,6 +673,17 @@ public:
template <class _Up> struct rebind {typedef allocator<_Up> other;};
};
+template <>
+class _LIBCPP_VISIBLE allocator<const void>
+{
+public:
+ typedef const void* pointer;
+ typedef const void* const_pointer;
+ typedef const void value_type;
+
+ template <class _Up> struct rebind {typedef allocator<_Up> other;};
+};
+
// pointer_traits
template <class _Tp>
@@ -1062,10 +1071,10 @@ struct __const_void_pointer<_Ptr, _Alloc, false>
#endif
};
-template <class _T>
+template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
-_T*
-__to_raw_pointer(_T* __p) _NOEXCEPT
+_Tp*
+__to_raw_pointer(_Tp* __p) _NOEXCEPT
{
return __p;
}
@@ -1387,6 +1396,14 @@ struct __has_construct
{
};
+#else // _LIBCPP_HAS_NO_VARIADICS
+
+template <class _Alloc, class _Pointer, class _Args>
+struct __has_construct
+ : false_type
+{
+};
+
#endif // _LIBCPP_HAS_NO_VARIADICS
template <class _Alloc, class _Pointer>
@@ -1516,6 +1533,60 @@ struct _LIBCPP_VISIBLE allocator_traits
__has_select_on_container_copy_construction<const allocator_type>(),
__a);}
+ template <class _Ptr>
+ _LIBCPP_INLINE_VISIBILITY
+ static
+ void
+ __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
+ {
+ for (; __begin1 != __end1; ++__begin1, ++__begin2)
+ construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
+ }
+
+ template <class _Tp>
+ _LIBCPP_INLINE_VISIBILITY
+ static
+ typename enable_if
+ <
+ (is_same<allocator_type, allocator<_Tp> >::value
+ || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
+ is_trivially_move_constructible<_Tp>::value,
+ void
+ >::type
+ __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
+ {
+ ptrdiff_t _Np = __end1 - __begin1;
+ _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
+ __begin2 += _Np;
+ }
+
+ template <class _Ptr>
+ _LIBCPP_INLINE_VISIBILITY
+ static
+ void
+ __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
+ {
+ while (__end1 != __begin1)
+ construct(__a, _VSTD::__to_raw_pointer(--__end2), _VSTD::move_if_noexcept(*--__end1));
+ }
+
+ template <class _Tp>
+ _LIBCPP_INLINE_VISIBILITY
+ static
+ typename enable_if
+ <
+ (is_same<allocator_type, allocator<_Tp> >::value
+ || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
+ is_trivially_move_constructible<_Tp>::value,
+ void
+ >::type
+ __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
+ {
+ ptrdiff_t _Np = __end1 - __begin1;
+ __end2 -= _Np;
+ _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
+ }
+
private:
_LIBCPP_INLINE_VISIBILITY
@@ -1524,7 +1595,7 @@ private:
{return __a.allocate(__n, __hint);}
_LIBCPP_INLINE_VISIBILITY
static pointer allocate(allocator_type& __a, size_type __n,
- const_void_pointer __hint, false_type)
+ const_void_pointer, false_type)
{return __a.allocate(__n);}
#ifndef _LIBCPP_HAS_NO_VARIADICS
@@ -1568,69 +1639,127 @@ private:
{return __a;}
};
-// uses_allocator
+// allocator
template <class _Tp>
-struct __has_allocator_type
+class _LIBCPP_VISIBLE allocator
{
-private:
- struct __two {char _; char __;};
- template <class _Up> static __two __test(...);
- template <class _Up> static char __test(typename _Up::allocator_type* = 0);
public:
- static const bool value = sizeof(__test<_Tp>(0)) == 1;
-};
-
-template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
-struct __uses_allocator
- : public integral_constant<bool,
- is_convertible<_Alloc, typename _Tp::allocator_type>::value>
-{
-};
-
-template <class _Tp, class _Alloc>
-struct __uses_allocator<_Tp, _Alloc, false>
- : public false_type
-{
-};
-
-template <class _Tp, class _Alloc>
-struct _LIBCPP_VISIBLE uses_allocator
- : public __uses_allocator<_Tp, _Alloc>
-{
-};
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef _Tp* pointer;
+ typedef const _Tp* const_pointer;
+ typedef _Tp& reference;
+ typedef const _Tp& const_reference;
+ typedef _Tp value_type;
-#ifndef _LIBCPP_HAS_NO_VARIADICS
+ typedef true_type propagate_on_container_move_assignment;
-// uses-allocator construction
+ template <class _Up> struct rebind {typedef allocator<_Up> other;};
-template <class _Tp, class _Alloc, class ..._Args>
-struct __uses_alloc_ctor_imp
-{
- static const bool __ua = uses_allocator<_Tp, _Alloc>::value;
- static const bool __ic =
- is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
- static const int value = __ua ? 2 - __ic : 0;
+ _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
+ template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
+ _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
+ {return _VSTD::addressof(__x);}
+ _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
+ {return _VSTD::addressof(__x);}
+ _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
+ {return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));}
+ _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
+ {::operator delete((void*)__p);}
+ _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
+ {return size_type(~0) / sizeof(_Tp);}
+#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
+ template <class _Up, class... _Args>
+ _LIBCPP_INLINE_VISIBILITY
+ void
+ construct(_Up* __p, _Args&&... __args)
+ {
+ ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
+ }
+#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
+ _LIBCPP_INLINE_VISIBILITY
+ void
+ construct(pointer __p)
+ {
+ ::new((void*)__p) _Tp();
+ }
+# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
+ template <class _A0>
+ _LIBCPP_INLINE_VISIBILITY
+ typename enable_if
+ <
+ !is_convertible<_A0, __rv<_A0> >::value,
+ void
+ >::type
+ construct(pointer __p, _A0& __a0)
+ {
+ ::new((void*)__p) _Tp(__a0);
+ }
+ template <class _A0>
+ _LIBCPP_INLINE_VISIBILITY
+ typename enable_if
+ <
+ !is_convertible<_A0, __rv<_A0> >::value,
+ void
+ >::type
+ construct(pointer __p, const _A0& __a0)
+ {
+ ::new((void*)__p) _Tp(__a0);
+ }
+ template <class _A0>
+ _LIBCPP_INLINE_VISIBILITY
+ typename enable_if
+ <
+ is_convertible<_A0, __rv<_A0> >::value,
+ void
+ >::type
+ construct(pointer __p, _A0 __a0)
+ {
+ ::new((void*)__p) _Tp(_VSTD::move(__a0));
+ }
+# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
+ template <class _A0, class _A1>
+ _LIBCPP_INLINE_VISIBILITY
+ void
+ construct(pointer __p, _A0& __a0, _A1& __a1)
+ {
+ ::new((void*)__p) _Tp(__a0, __a1);
+ }
+ template <class _A0, class _A1>
+ _LIBCPP_INLINE_VISIBILITY
+ void
+ construct(pointer __p, const _A0& __a0, _A1& __a1)
+ {
+ ::new((void*)__p) _Tp(__a0, __a1);
+ }
+ template <class _A0, class _A1>
+ _LIBCPP_INLINE_VISIBILITY
+ void
+ construct(pointer __p, _A0& __a0, const _A1& __a1)
+ {
+ ::new((void*)__p) _Tp(__a0, __a1);
+ }
+ template <class _A0, class _A1>
+ _LIBCPP_INLINE_VISIBILITY
+ void
+ construct(pointer __p, const _A0& __a0, const _A1& __a1)
+ {
+ ::new((void*)__p) _Tp(__a0, __a1);
+ }
+#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
+ _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
};
-template <class _Tp, class _Alloc, class ..._Args>
-struct __uses_alloc_ctor
- : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value>
- {};
-
-#endif // _LIBCPP_HAS_NO_VARIADICS
-
-// allocator
-
template <class _Tp>
-class _LIBCPP_VISIBLE allocator
+class _LIBCPP_VISIBLE allocator<const _Tp>
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
- typedef _Tp* pointer;
+ typedef const _Tp* pointer;
typedef const _Tp* const_pointer;
- typedef _Tp& reference;
+ typedef const _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
@@ -1640,8 +1769,6 @@ public:
_LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
- _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
- {return _VSTD::addressof(__x);}
_LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
{return _VSTD::addressof(__x);}
_LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
@@ -1846,8 +1973,16 @@ public:
template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
typename remove_cv<_T2>::type>::value,
- bool = is_empty<_T1>::value,
- bool = is_empty<_T2>::value>
+ bool = is_empty<_T1>::value
+#if __has_feature(is_final)
+ && !__is_final(_T1)
+#endif
+ ,
+ bool = is_empty<_T2>::value
+#if __has_feature(is_final)
+ && !__is_final(_T2)
+#endif
+ >
struct __libcpp_compressed_pair_switch;
template <class _T1, class _T2, bool IsSame>
@@ -1885,9 +2020,9 @@ public:
typedef const typename remove_reference<_T2>::type& _T2_const_reference;
_LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
- _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1, int = 0)
+ _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
: __first_(_VSTD::forward<_T1_param>(__t1)) {}
- _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2, int* = 0)
+ _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
: __second_(_VSTD::forward<_T2_param>(__t2)) {}
_LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
: __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
@@ -1930,6 +2065,21 @@ public:
return *this;
}
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+ template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
+ _LIBCPP_INLINE_VISIBILITY
+ __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
+ tuple<_Args1...> __first_args,
+ tuple<_Args2...> __second_args,
+ __tuple_indices<_I1...>,
+ __tuple_indices<_I2...>)
+ : __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
+ __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
+ {}
+
+#endif // _LIBCPP_HAS_NO_VARIADICS
+
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
@@ -1967,9 +2117,9 @@ public:
typedef const typename remove_reference<_T2>::type& _T2_const_reference;
_LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
- _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1, int = 0)
+ _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
: _T1(_VSTD::forward<_T1_param>(__t1)) {}
- _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2, int* = 0)
+ _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
: __second_(_VSTD::forward<_T2_param>(__t2)) {}
_LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
: _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
@@ -2010,6 +2160,21 @@ public:
return *this;
}
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+ template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
+ _LIBCPP_INLINE_VISIBILITY
+ __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
+ tuple<_Args1...> __first_args,
+ tuple<_Args2...> __second_args,
+ __tuple_indices<_I1...>,
+ __tuple_indices<_I2...>)
+ : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
+ __second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
+ {}
+
+#endif // _LIBCPP_HAS_NO_VARIADICS
+
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
@@ -2091,6 +2256,22 @@ public:
return *this;
}
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+ template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
+ _LIBCPP_INLINE_VISIBILITY
+ __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
+ tuple<_Args1...> __first_args,
+ tuple<_Args2...> __second_args,
+ __tuple_indices<_I1...>,
+ __tuple_indices<_I2...>)
+ : _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...),
+ __first_(_VSTD::forward<_Args1>(get<_I1>(__first_args))...)
+
+ {}
+
+#endif // _LIBCPP_HAS_NO_VARIADICS
+
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
@@ -2169,6 +2350,21 @@ public:
return *this;
}
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+ template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
+ _LIBCPP_INLINE_VISIBILITY
+ __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
+ tuple<_Args1...> __first_args,
+ tuple<_Args2...> __second_args,
+ __tuple_indices<_I1...>,
+ __tuple_indices<_I2...>)
+ : _T1(_VSTD::forward<_Args1>(get<_I1>(__first_args))...),
+ _T2(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
+ {}
+
+#endif // _LIBCPP_HAS_NO_VARIADICS
+
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
@@ -2179,7 +2375,7 @@ public:
_LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
_LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
- _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
+ _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
_NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
__is_nothrow_swappable<_T1>::value)
{
@@ -2202,9 +2398,9 @@ public:
typedef typename base::_T2_const_reference _T2_const_reference;
_LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
- _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1, int = 0)
+ _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
: base(_VSTD::forward<_T1_param>(__t1)) {}
- _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2, int* = 0)
+ _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
: base(_VSTD::forward<_T2_param>(__t2)) {}
_LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
: base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
@@ -2241,6 +2437,20 @@ public:
base::operator=(_VSTD::move(__p));
return *this;
}
+
+#ifndef _LIBCPP_HAS_NO_VARIADICS
+
+ template <class... _Args1, class... _Args2>
+ _LIBCPP_INLINE_VISIBILITY
+ __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
+ tuple<_Args2...> __second_args)
+ : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
+ typename __make_tuple_indices<sizeof...(_Args1)>::type(),
+ typename __make_tuple_indices<sizeof...(_Args2) >::type())
+ {}
+
+#endif // _LIBCPP_HAS_NO_VARIADICS
+
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
@@ -2265,6 +2475,31 @@ swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
__is_nothrow_swappable<_T1>::value)
{__x.swap(__y);}
+// __same_or_less_cv_qualified
+
+template <class _Ptr1, class _Ptr2,
+ bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
+ typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
+ >::value
+ >
+struct __same_or_less_cv_qualified_imp
+ : is_convertible<_Ptr1, _Ptr2> {};
+
+template <class _Ptr1, class _Ptr2>
+struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
+ : false_type {};
+
+template <class _Ptr1, class _Ptr2, bool = is_scalar<_Ptr1>::value &&
+ !is_pointer<_Ptr1>::value>
+struct __same_or_less_cv_qualified
+ : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
+
+template <class _Ptr1, class _Ptr2>
+struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, true>
+ : false_type {};
+
+// default_delete
+
template <class _Tp>
struct _LIBCPP_VISIBLE default_delete
{
@@ -2282,13 +2517,19 @@ struct _LIBCPP_VISIBLE default_delete
template <class _Tp>
struct _LIBCPP_VISIBLE default_delete<_Tp[]>
{
- _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
+public:
+ _LIBCPP_INLINE_VISIBILITY default_delete() _NOEXCEPT {}
+ template <class _Up>
+ _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
+ typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
+ template <class _Up>
+ _LIBCPP_INLINE_VISIBILITY
+ void operator() (_Up* __ptr,
+ typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
{
static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
delete [] __ptr;
}
-private:
- template <class _Up> void operator() (_Up*) const;
};
template <class _Tp, class _Dp = default_delete<_Tp> >
@@ -2301,14 +2542,7 @@ public:
private:
__compressed_pair<pointer, deleter_type> __ptr_;
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- unique_ptr(const unique_ptr&);
- unique_ptr& operator=(const unique_ptr&);
- template <class _Up, class _Ep>
- unique_ptr(const unique_ptr<_Up, _Ep>&);
- template <class _Up, class _Ep>
- unique_ptr& operator=(const unique_ptr<_Up, _Ep>&);
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
unique_ptr(unique_ptr&);
template <class _Up, class _Ep>
unique_ptr(unique_ptr<_Up, _Ep>&);
@@ -2395,7 +2629,9 @@ public:
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
- !is_array<_Up>::value,
+ !is_array<_Up>::value &&
+ is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
+ is_assignable<deleter_type&, _Ep&&>::value,
unique_ptr&
>::type
operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
@@ -2452,9 +2688,9 @@ public:
{return __ptr_.second();}
_LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
{return __ptr_.second();}
- _LIBCPP_INLINE_VISIBILITY operator int __nat::*() const
- _NOEXCEPT
- {return __ptr_.first() ? &__nat::__for_bool_ : 0;}
+ _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
+ {return __ptr_.first() != nullptr;}
_LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
{
@@ -2485,10 +2721,7 @@ public:
private:
__compressed_pair<pointer, deleter_type> __ptr_;
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- unique_ptr(const unique_ptr&);
- unique_ptr& operator=(const unique_ptr&);
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
unique_ptr(unique_ptr&);
template <class _Up>
unique_ptr(unique_ptr<_Up>&);
@@ -2515,20 +2748,20 @@ public:
"unique_ptr constructed with null function pointer deleter");
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _P,
- class = typename enable_if<is_same<_P, pointer>::value>::type
+ template <class _Pp,
+ class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
>
- _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_P __p) _NOEXCEPT
+ _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p) _NOEXCEPT
: __ptr_(__p)
{
static_assert(!is_pointer<deleter_type>::value,
"unique_ptr constructed with null function pointer deleter");
}
- template <class _P,
- class = typename enable_if<is_same<_P, pointer>::value>::type
+ template <class _Pp,
+ class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
>
- _LIBCPP_INLINE_VISIBILITY unique_ptr(_P __p, typename conditional<
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
is_reference<deleter_type>::value,
deleter_type,
typename add_lvalue_reference<const deleter_type>::type>::type __d)
@@ -2542,11 +2775,10 @@ public:
_NOEXCEPT
: __ptr_(pointer(), __d) {}
- template <class _P,
- class = typename enable_if<is_same<_P, pointer>::value ||
- is_same<_P, nullptr_t>::value>::type
+ template <class _Pp,
+ class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
>
- _LIBCPP_INLINE_VISIBILITY unique_ptr(_P __p, typename remove_reference<deleter_type>::type&& __d)
+ _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename remove_reference<deleter_type>::type&& __d)
_NOEXCEPT
: __ptr_(__p, _VSTD::move(__d))
{
@@ -2569,6 +2801,40 @@ public:
__ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
return *this;
}
+
+ template <class _Up, class _Ep>
+ _LIBCPP_INLINE_VISIBILITY
+ unique_ptr(unique_ptr<_Up, _Ep>&& __u,
+ typename enable_if
+ <
+ is_array<_Up>::value &&
+ __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
+ && is_convertible<_Ep, deleter_type>::value &&
+ (
+ !is_reference<deleter_type>::value ||
+ is_same<deleter_type, _Ep>::value
+ ),
+ __nat
+ >::type = __nat()
+ ) _NOEXCEPT
+ : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
+
+
+ template <class _Up, class _Ep>
+ _LIBCPP_INLINE_VISIBILITY
+ typename enable_if
+ <
+ is_array<_Up>::value &&
+ __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
+ is_assignable<deleter_type&, _Ep&&>::value,
+ unique_ptr&
+ >::type
+ operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
+ {
+ reset(__u.release());
+ __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
+ return *this;
+ }
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
@@ -2615,8 +2881,9 @@ public:
{return __ptr_.second();}
_LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
{return __ptr_.second();}
- _LIBCPP_INLINE_VISIBILITY operator int __nat::*() const _NOEXCEPT
- {return __ptr_.first() ? &__nat::__for_bool_ : 0;}
+ _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
+ {return __ptr_.first() != nullptr;}
_LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
{
@@ -2626,10 +2893,10 @@ public:
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _P,
- class = typename enable_if<is_same<_P, pointer>::value>::type
+ template <class _Pp,
+ class = typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value>::type
>
- _LIBCPP_INLINE_VISIBILITY void reset(_P __p) _NOEXCEPT
+ _LIBCPP_INLINE_VISIBILITY void reset(_Pp __p) _NOEXCEPT
{
pointer __tmp = __ptr_.first();
__ptr_.first() = __p;
@@ -2698,7 +2965,13 @@ operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {re
template <class _T1, class _D1, class _T2, class _D2>
inline _LIBCPP_INLINE_VISIBILITY
bool
-operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() < __y.get();}
+operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
+{
+ typedef typename unique_ptr<_T1, _D1>::pointer _P1;
+ typedef typename unique_ptr<_T2, _D2>::pointer _P2;
+ typedef typename common_type<_P1, _P2>::type _V;
+ return less<_V>()(__x.get(), __y.get());
+}
template <class _T1, class _D1, class _T2, class _D2>
inline _LIBCPP_INLINE_VISIBILITY
@@ -2715,20 +2988,425 @@ inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t)
+{
+ return !__x;
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x)
+{
+ return !__x;
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
+{
+ return static_cast<bool>(__x);
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
+{
+ return static_cast<bool>(__x);
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
+{
+ typedef typename unique_ptr<_T1, _D1>::pointer _P1;
+ return less<_P1>()(__x.get(), nullptr);
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
+{
+ typedef typename unique_ptr<_T1, _D1>::pointer _P1;
+ return less<_P1>()(nullptr, __x.get());
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
+{
+ return nullptr < __x;
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
+{
+ return __x < nullptr;
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
+{
+ return !(nullptr < __x);
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
+{
+ return !(__x < nullptr);
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
+{
+ return !(__x < nullptr);
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
+{
+ return !(nullptr < __x);
+}
+
template <class _Tp> struct hash;
-template<class _Tp>
-struct _LIBCPP_VISIBLE hash<_Tp*>
- : public unary_function<_Tp*, size_t>
+// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
+// is 64 bits. This is because cityhash64 uses 64bit x 64bit
+// multiplication, which can be very slow on 32-bit systems.
+template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
+struct __murmur2_or_cityhash;
+
+template <class _Size>
+struct __murmur2_or_cityhash<_Size, 32>
+{
+ _Size operator()(const void* __key, _Size __len);
+};
+
+// murmur2
+template <class _Size>
+_Size
+__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
+{
+ const _Size __m = 0x5bd1e995;
+ const _Size __r = 24;
+ _Size __h = __len;
+ const unsigned char* __data = static_cast<const unsigned char*>(__key);
+ for (; __len >= 4; __data += 4, __len -= 4)
+ {
+ _Size __k = *(const _Size*)__data;
+ __k *= __m;
+ __k ^= __k >> __r;
+ __k *= __m;
+ __h *= __m;
+ __h ^= __k;
+ }
+ switch (__len)
+ {
+ case 3:
+ __h ^= __data[2] << 16;
+ case 2:
+ __h ^= __data[1] << 8;
+ case 1:
+ __h ^= __data[0];
+ __h *= __m;
+ }
+ __h ^= __h >> 13;
+ __h *= __m;
+ __h ^= __h >> 15;
+ return __h;
+}
+
+template <class _Size>
+struct __murmur2_or_cityhash<_Size, 64>
+{
+ _Size operator()(const void* __key, _Size __len);
+
+ private:
+ // Some primes between 2^63 and 2^64.
+ static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
+ static const _Size __k1 = 0xb492b66fbe98f273ULL;
+ static const _Size __k2 = 0x9ae16a3b2f90404fULL;
+ static const _Size __k3 = 0xc949d7c7509e6557ULL;
+
+ static _Size __rotate(_Size __val, int __shift) {
+ return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
+ }
+
+ static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
+ return (__val >> __shift) | (__val << (64 - __shift));
+ }
+
+ static _Size __shift_mix(_Size __val) {
+ return __val ^ (__val >> 47);
+ }
+
+ static _Size __hash_len_16(_Size __u, _Size __v) {
+ const _Size __mul = 0x9ddfea08eb382d69ULL;
+ _Size __a = (__u ^ __v) * __mul;
+ __a ^= (__a >> 47);
+ _Size __b = (__v ^ __a) * __mul;
+ __b ^= (__b >> 47);
+ __b *= __mul;
+ return __b;
+ }
+
+ static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
+ if (__len > 8) {
+ const _Size __a = *(const _Size*)__s;
+ const _Size __b = *(const _Size*)(__s + __len - 8);
+ return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
+ }
+ if (__len >= 4) {
+ const uint32_t __a = *(const uint32_t*)(__s);
+ const uint32_t __b = *(const uint32_t*)(__s + __len - 4);
+ return __hash_len_16(__len + (__a << 3), __b);
+ }
+ if (__len > 0) {
+ const unsigned char __a = __s[0];
+ const unsigned char __b = __s[__len >> 1];
+ const unsigned char __c = __s[__len - 1];
+ const uint32_t __y = static_cast<uint32_t>(__a) +
+ (static_cast<uint32_t>(__b) << 8);
+ const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
+ return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
+ }
+ return __k2;
+ }
+
+ static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
+ const _Size __a = *(const _Size*)(__s) * __k1;
+ const _Size __b = *(const _Size*)(__s + 8);
+ const _Size __c = *(const _Size*)(__s + __len - 8) * __k2;
+ const _Size __d = *(const _Size*)(__s + __len - 16) * __k0;
+ return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
+ __a + __rotate(__b ^ __k3, 20) - __c + __len);
+ }
+
+ // Return a 16-byte hash for 48 bytes. Quick and dirty.
+ // Callers do best to use "random-looking" values for a and b.
+ static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
+ _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
+ __a += __w;
+ __b = __rotate(__b + __a + __z, 21);
+ const _Size __c = __a;
+ __a += __x;
+ __a += __y;
+ __b += __rotate(__a, 44);
+ return pair<_Size, _Size>(__a + __z, __b + __c);
+ }
+
+ // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
+ static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
+ const char* __s, _Size __a, _Size __b) {
+ return __weak_hash_len_32_with_seeds(*(const _Size*)(__s),
+ *(const _Size*)(__s + 8),
+ *(const _Size*)(__s + 16),
+ *(const _Size*)(__s + 24),
+ __a,
+ __b);
+ }
+
+ // Return an 8-byte hash for 33 to 64 bytes.
+ static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
+ _Size __z = *(const _Size*)(__s + 24);
+ _Size __a = *(const _Size*)(__s) +
+ (__len + *(const _Size*)(__s + __len - 16)) * __k0;
+ _Size __b = __rotate(__a + __z, 52);
+ _Size __c = __rotate(__a, 37);
+ __a += *(const _Size*)(__s + 8);
+ __c += __rotate(__a, 7);
+ __a += *(const _Size*)(__s + 16);
+ _Size __vf = __a + __z;
+ _Size __vs = __b + __rotate(__a, 31) + __c;
+ __a = *(const _Size*)(__s + 16) + *(const _Size*)(__s + __len - 32);
+ __z += *(const _Size*)(__s + __len - 8);
+ __b = __rotate(__a + __z, 52);
+ __c = __rotate(__a, 37);
+ __a += *(const _Size*)(__s + __len - 24);
+ __c += __rotate(__a, 7);
+ __a += *(const _Size*)(__s + __len - 16);
+ _Size __wf = __a + __z;
+ _Size __ws = __b + __rotate(__a, 31) + __c;
+ _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
+ return __shift_mix(__r * __k0 + __vs) * __k2;
+ }
+};
+
+// cityhash64
+template <class _Size>
+_Size
+__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
+{
+ const char* __s = static_cast<const char*>(__key);
+ if (__len <= 32) {
+ if (__len <= 16) {
+ return __hash_len_0_to_16(__s, __len);
+ } else {
+ return __hash_len_17_to_32(__s, __len);
+ }
+ } else if (__len <= 64) {
+ return __hash_len_33_to_64(__s, __len);
+ }
+
+ // For strings over 64 bytes we hash the end first, and then as we
+ // loop we keep 56 bytes of state: v, w, x, y, and z.
+ _Size __x = *(const _Size*)(__s + __len - 40);
+ _Size __y = *(const _Size*)(__s + __len - 16) +
+ *(const _Size*)(__s + __len - 56);
+ _Size __z = __hash_len_16(*(const _Size*)(__s + __len - 48) + __len,
+ *(const _Size*)(__s + __len - 24));
+ pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
+ pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
+ __x = __x * __k1 + *(const _Size*)(__s);
+
+ // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
+ __len = (__len - 1) & ~static_cast<_Size>(63);
+ do {
+ __x = __rotate(__x + __y + __v.first + *(const _Size*)(__s + 8), 37) * __k1;
+ __y = __rotate(__y + __v.second + *(const _Size*)(__s + 48), 42) * __k1;
+ __x ^= __w.second;
+ __y += __v.first + *(const _Size*)(__s + 40);
+ __z = __rotate(__z + __w.first, 33) * __k1;
+ __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
+ __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
+ __y + *(const _Size*)(__s + 16));
+ std::swap(__z, __x);
+ __s += 64;
+ __len -= 64;
+ } while (__len != 0);
+ return __hash_len_16(
+ __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
+ __hash_len_16(__v.second, __w.second) + __x);
+}
+
+template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
+struct __scalar_hash;
+
+template <class _Tp>
+struct __scalar_hash<_Tp, 0>
+ : public unary_function<_Tp, size_t>
+{
+ _LIBCPP_INLINE_VISIBILITY
+ size_t operator()(_Tp __v) const _NOEXCEPT
+ {
+ union
+ {
+ _Tp __t;
+ size_t __a;
+ } __u;
+ __u.__a = 0;
+ __u.__t = __v;
+ return __u.__a;
+ }
+};
+
+template <class _Tp>
+struct __scalar_hash<_Tp, 1>
+ : public unary_function<_Tp, size_t>
+{
+ _LIBCPP_INLINE_VISIBILITY
+ size_t operator()(_Tp __v) const _NOEXCEPT
+ {
+ union
+ {
+ _Tp __t;
+ size_t __a;
+ } __u;
+ __u.__t = __v;
+ return __u.__a;
+ }
+};
+
+template <class _Tp>
+struct __scalar_hash<_Tp, 2>
+ : public unary_function<_Tp, size_t>
+{
+ _LIBCPP_INLINE_VISIBILITY
+ size_t operator()(_Tp __v) const _NOEXCEPT
+ {
+ union
+ {
+ _Tp __t;
+ struct
+ {
+ size_t __a;
+ size_t __b;
+ };
+ } __u;
+ __u.__t = __v;
+ return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
+ }
+};
+
+template <class _Tp>
+struct __scalar_hash<_Tp, 3>
+ : public unary_function<_Tp, size_t>
{
_LIBCPP_INLINE_VISIBILITY
- size_t operator()(_Tp* __v) const _NOEXCEPT
+ size_t operator()(_Tp __v) const _NOEXCEPT
{
- const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
- return *__p;
+ union
+ {
+ _Tp __t;
+ struct
+ {
+ size_t __a;
+ size_t __b;
+ size_t __c;
+ };
+ } __u;
+ __u.__t = __v;
+ return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
}
};
+template <class _Tp>
+struct __scalar_hash<_Tp, 4>
+ : public unary_function<_Tp, size_t>
+{
+ _LIBCPP_INLINE_VISIBILITY
+ size_t operator()(_Tp __v) const _NOEXCEPT
+ {
+ union
+ {
+ _Tp __t;
+ struct
+ {
+ size_t __a;
+ size_t __b;
+ size_t __c;
+ size_t __d;
+ };
+ } __u;
+ __u.__t = __v;
+ return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
+ }
+};
+
+template<class _Tp>
+struct _LIBCPP_VISIBLE hash<_Tp*>
+ : public __scalar_hash<_Tp*>
+{
+};
+
template <class _Tp, class _Dp>
struct _LIBCPP_VISIBLE hash<unique_ptr<_Tp, _Dp> >
{
@@ -2804,12 +3482,23 @@ template <class _InputIterator, class _ForwardIterator>
_ForwardIterator
uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
{
- __destruct_n __d(0);
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
- unique_ptr<value_type, __destruct_n&> __h(&*__r, __d);
- for (; __f != __l; ++__f, ++__r, __d.__incr((value_type*)0))
- ::new(&*__r) value_type(*__f);
- __h.release();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ _ForwardIterator __s = __r;
+ try
+ {
+#endif
+ for (; __f != __l; ++__f, ++__r)
+ ::new(&*__r) value_type(*__f);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ for (; __s != __r; ++__s)
+ __s->~value_type();
+ throw;
+ }
+#endif
return __r;
}
@@ -2817,12 +3506,23 @@ template <class _InputIterator, class _Size, class _ForwardIterator>
_ForwardIterator
uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
{
- __destruct_n __d(0);
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
- unique_ptr<value_type, __destruct_n&> __h(&*__r, __d);
- for (; __n > 0; ++__f, ++__r, __d.__incr((value_type*)0), --__n)
- ::new(&*__r) value_type(*__f);
- __h.release();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ _ForwardIterator __s = __r;
+ try
+ {
+#endif
+ for (; __n > 0; ++__f, ++__r, --__n)
+ ::new(&*__r) value_type(*__f);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ for (; __s != __r; ++__s)
+ __s->~value_type();
+ throw;
+ }
+#endif
return __r;
}
@@ -2830,24 +3530,46 @@ template <class _ForwardIterator, class _Tp>
void
uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
{
- __destruct_n __d(0);
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
- unique_ptr<value_type, __destruct_n&> __h(&*__f, __d);
- for (; __f != __l; ++__f, __d.__incr((value_type*)0))
- ::new(&*__f) value_type(__x);
- __h.release();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ _ForwardIterator __s = __f;
+ try
+ {
+#endif
+ for (; __f != __l; ++__f)
+ ::new(&*__f) value_type(__x);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ for (; __s != __f; ++__s)
+ __s->~value_type();
+ throw;
+ }
+#endif
}
template <class _ForwardIterator, class _Size, class _Tp>
_ForwardIterator
uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
{
- __destruct_n __d(0);
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
- unique_ptr<value_type, __destruct_n&> __h(&*__f, __d);
- for (; __n > 0; ++__f, --__n, __d.__incr((value_type*)0))
- ::new(&*__f) value_type(__x);
- __h.release();
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ _ForwardIterator __s = __f;
+ try
+ {
+#endif
+ for (; __n > 0; ++__f, --__n)
+ ::new(&*__f) value_type(__x);
+#ifndef _LIBCPP_NO_EXCEPTIONS
+ }
+ catch (...)
+ {
+ for (; __s != __f; ++__s)
+ __s->~value_type();
+ throw;
+ }
+#endif
return __f;
}
@@ -2972,7 +3694,8 @@ public:
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
__shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
- : __data_(_VSTD::move(__a), _Tp(_VSTD::forward<_Args>(__args)...)) {}
+ : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
+ _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
#else // _LIBCPP_HAS_NO_VARIADICS
@@ -3036,9 +3759,27 @@ private:
public:
shared_ptr() _NOEXCEPT;
shared_ptr(nullptr_t) _NOEXCEPT;
- template<class _Yp> explicit shared_ptr(_Yp* __p);
- template<class _Yp, class _Dp> shared_ptr(_Yp* __p, _Dp __d);
- template<class _Yp, class _Dp, class _Alloc> shared_ptr(_Yp* __p, _Dp __d, _Alloc __a);
+ template<class _Yp,
+ class = typename enable_if
+ <
+ is_convertible<_Yp*, element_type*>::value
+ >::type
+ >
+ explicit shared_ptr(_Yp* __p);
+ template<class _Yp, class _Dp,
+ class = typename enable_if
+ <
+ is_convertible<_Yp*, element_type*>::value
+ >::type
+ >
+ shared_ptr(_Yp* __p, _Dp __d);
+ template<class _Yp, class _Dp, class _Alloc,
+ class = typename enable_if
+ <
+ is_convertible<_Yp*, element_type*>::value
+ >::type
+ >
+ shared_ptr(_Yp* __p, _Dp __d, _Alloc __a);
template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
template<class _Yp> shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
@@ -3056,50 +3797,134 @@ public:
template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template<class _Yp> shared_ptr(auto_ptr<_Yp>&& __r);
+ template<class _Yp,
+ class = typename enable_if
+ <
+ is_convertible<_Yp*, element_type*>::value
+ >::type
+ >
+ shared_ptr(auto_ptr<_Yp>&& __r);
#else
- template<class _Yp> shared_ptr(auto_ptr<_Yp> __r);
+ template<class _Yp,
+ class = typename enable_if
+ <
+ is_convertible<_Yp*, element_type*>::value
+ >::type
+ >
+ shared_ptr(auto_ptr<_Yp> __r);
#endif
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-private:
- template <class _Yp, class _Dp> shared_ptr(const unique_ptr<_Yp, _Dp>& __r);// = delete;
-public:
- template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>&&,
+ template <class _Yp, class _Dp,
+ class = typename enable_if
+ <
+ !is_array<_Yp>::value &&
+ is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
+ >::type
+ >
+ shared_ptr(unique_ptr<_Yp, _Dp>&&,
typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
- template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>&&,
+ template <class _Yp, class _Dp,
+ class = typename enable_if
+ <
+ !is_array<_Yp>::value &&
+ is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
+ >::type
+ >
+ shared_ptr(unique_ptr<_Yp, _Dp>&&,
typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>,
+ template <class _Yp, class _Dp,
+ class = typename enable_if
+ <
+ !is_array<_Yp>::value &&
+ is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
+ >::type
+ > shared_ptr(unique_ptr<_Yp, _Dp>,
typename enable_if<!is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
- template <class _Yp, class _Dp> shared_ptr(unique_ptr<_Yp, _Dp>,
+ template <class _Yp, class _Dp,
+ class = typename enable_if
+ <
+ !is_array<_Yp>::value &&
+ is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value
+ >::type
+ >
+ shared_ptr(unique_ptr<_Yp, _Dp>,
typename enable_if<is_lvalue_reference<_Dp>::value, __nat>::type = __nat());
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
~shared_ptr();
shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
- template<class _Yp> shared_ptr& operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
+ template<class _Yp>
+ typename enable_if
+ <
+ is_convertible<_Yp*, element_type*>::value,
+ shared_ptr&
+ >::type
+ operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
- template<class _Yp> shared_ptr& operator=(shared_ptr<_Yp>&& __r);
- template<class _Yp> shared_ptr& operator=(auto_ptr<_Yp>&& __r);
+ template<class _Yp>
+ typename enable_if
+ <
+ is_convertible<_Yp*, element_type*>::value,
+ shared_ptr<_Tp>&
+ >::type
+ operator=(shared_ptr<_Yp>&& __r);
+ template<class _Yp>
+ typename enable_if
+ <
+ !is_array<_Yp>::value &&
+ is_convertible<_Yp*, element_type*>::value,
+ shared_ptr&
+ >::type
+ operator=(auto_ptr<_Yp>&& __r);
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template<class _Yp> shared_ptr& operator=(auto_ptr<_Yp> __r);
+ template<class _Yp>
+ typename enable_if
+ <
+ !is_array<_Yp>::value &&
+ is_convertible<_Yp*, element_type*>::value,
+ shared_ptr&
+ >::type
+ operator=(auto_ptr<_Yp> __r);
#endif
+ template <class _Yp, class _Dp>
+ typename enable_if
+ <
+ !is_array<_Yp>::value &&
+ is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
+ shared_ptr&
+ >::type
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
-private:
- template <class _Yp, class _Dp> shared_ptr& operator=(const unique_ptr<_Yp, _Dp>& __r);// = delete;
-public:
- template <class _Yp, class _Dp> shared_ptr& operator=(unique_ptr<_Yp, _Dp>&& __r);
+ operator=(unique_ptr<_Yp, _Dp>&& __r);
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class _Yp, class _Dp> shared_ptr& operator=(unique_ptr<_Yp, _Dp> __r);
+ operator=(unique_ptr<_Yp, _Dp> __r);
#endif
void swap(shared_ptr& __r) _NOEXCEPT;
void reset() _NOEXCEPT;
- template<class _Yp> void reset(_Yp* __p) _NOEXCEPT;
- template<class _Yp, class _Dp> void reset(_Yp* __p, _Dp __d);
- template<class _Yp, class _Dp, class _Alloc> void reset(_Yp* __p, _Dp __d, _Alloc __a);
+ template<class _Yp>
+ typename enable_if
+ <
+ is_convertible<_Yp*, element_type*>::value,
+ void
+ >::type
+ reset(_Yp* __p);
+ template<class _Yp, class _Dp>
+ typename enable_if
+ <
+ is_convertible<_Yp*, element_type*>::value,
+ void
+ >::type
+ reset(_Yp* __p, _Dp __d);
+ template<class _Yp, class _Dp, class _Alloc>
+ typename enable_if
+ <
+ is_convertible<_Yp*, element_type*>::value,
+ void
+ >::type
+ reset(_Yp* __p, _Dp __d, _Alloc __a);
_LIBCPP_INLINE_VISIBILITY
element_type* get() const _NOEXCEPT {return __ptr_;}
@@ -3113,14 +3938,14 @@ public:
_LIBCPP_INLINE_VISIBILITY
bool unique() const _NOEXCEPT {return use_count() == 1;}
_LIBCPP_INLINE_VISIBILITY
- /*explicit*/ operator bool() const _NOEXCEPT {return get() != 0;}
- template <class _U>
+ _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
+ template <class _Up>
_LIBCPP_INLINE_VISIBILITY
- bool owner_before(shared_ptr<_U> const& __p) const
+ bool owner_before(shared_ptr<_Up> const& __p) const
{return __cntrl_ < __p.__cntrl_;}
- template <class _U>
+ template <class _Up>
_LIBCPP_INLINE_VISIBILITY
- bool owner_before(weak_ptr<_U> const& __p) const
+ bool owner_before(weak_ptr<_Up> const& __p) const
{return __cntrl_ < __p.__cntrl_;}
#ifndef _LIBCPP_NO_RTTI
@@ -3208,7 +4033,7 @@ shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
}
template<class _Tp>
-template<class _Yp>
+template<class _Yp, class>
shared_ptr<_Tp>::shared_ptr(_Yp* __p)
: __ptr_(__p)
{
@@ -3220,7 +4045,7 @@ shared_ptr<_Tp>::shared_ptr(_Yp* __p)
}
template<class _Tp>
-template<class _Yp, class _Dp>
+template<class _Yp, class _Dp, class>
shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d)
: __ptr_(__p)
{
@@ -3263,7 +4088,7 @@ shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
}
template<class _Tp>
-template<class _Yp, class _Dp, class _Alloc>
+template<class _Yp, class _Dp, class _Alloc, class>
shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a)
: __ptr_(__p)
{
@@ -3377,7 +4202,7 @@ shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template<class _Tp>
-template<class _Yp>
+template<class _Yp, class>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r)
#else
@@ -3392,7 +4217,7 @@ shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r)
}
template<class _Tp>
-template <class _Yp, class _Dp>
+template <class _Yp, class _Dp, class>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
#else
@@ -3408,7 +4233,7 @@ shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
}
template<class _Tp>
-template <class _Yp, class _Dp>
+template <class _Yp, class _Dp, class>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
#else
@@ -3629,7 +4454,11 @@ shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
template<class _Tp>
template<class _Yp>
inline _LIBCPP_INLINE_VISIBILITY
-shared_ptr<_Tp>&
+typename enable_if
+<
+ is_convertible<_Yp*, _Tp*>::value,
+ shared_ptr<_Tp>&
+>::type
shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
{
shared_ptr(__r).swap(*this);
@@ -3650,7 +4479,11 @@ shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
template<class _Tp>
template<class _Yp>
inline _LIBCPP_INLINE_VISIBILITY
-shared_ptr<_Tp>&
+typename enable_if
+<
+ is_convertible<_Yp*, _Tp*>::value,
+ shared_ptr<_Tp>&
+>::type
shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
{
shared_ptr(_VSTD::move(__r)).swap(*this);
@@ -3660,7 +4493,12 @@ shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
template<class _Tp>
template<class _Yp>
inline _LIBCPP_INLINE_VISIBILITY
-shared_ptr<_Tp>&
+typename enable_if
+<
+ !is_array<_Yp>::value &&
+ is_convertible<_Yp*, _Tp*>::value,
+ shared_ptr<_Tp>&
+>::type
shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
{
shared_ptr(_VSTD::move(__r)).swap(*this);
@@ -3670,7 +4508,12 @@ shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
template<class _Tp>
template <class _Yp, class _Dp>
inline _LIBCPP_INLINE_VISIBILITY
-shared_ptr<_Tp>&
+typename enable_if
+<
+ !is_array<_Yp>::value &&
+ is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
+ shared_ptr<_Tp>&
+>::type
shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
{
shared_ptr(_VSTD::move(__r)).swap(*this);
@@ -3682,7 +4525,12 @@ shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
template<class _Tp>
template<class _Yp>
inline _LIBCPP_INLINE_VISIBILITY
-shared_ptr<_Tp>&
+typename enable_if
+<
+ !is_array<_Yp>::value &&
+ is_convertible<_Yp*, _Tp*>::value,
+ shared_ptr<_Tp>&
+>::type
shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
{
shared_ptr(__r).swap(*this);
@@ -3692,7 +4540,12 @@ shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
template<class _Tp>
template <class _Yp, class _Dp>
inline _LIBCPP_INLINE_VISIBILITY
-shared_ptr<_Tp>&
+typename enable_if
+<
+ !is_array<_Yp>::value &&
+ is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
+ shared_ptr<_Tp>&
+>::type
shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
{
shared_ptr(_VSTD::move(__r)).swap(*this);
@@ -3721,7 +4574,11 @@ shared_ptr<_Tp>::reset() _NOEXCEPT
template<class _Tp>
template<class _Yp>
inline _LIBCPP_INLINE_VISIBILITY
-void
+typename enable_if
+<
+ is_convertible<_Yp*, _Tp*>::value,
+ void
+>::type
shared_ptr<_Tp>::reset(_Yp* __p)
{
shared_ptr(__p).swap(*this);
@@ -3730,7 +4587,11 @@ shared_ptr<_Tp>::reset(_Yp* __p)
template<class _Tp>
template<class _Yp, class _Dp>
inline _LIBCPP_INLINE_VISIBILITY
-void
+typename enable_if
+<
+ is_convertible<_Yp*, _Tp*>::value,
+ void
+>::type
shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
{
shared_ptr(__p, __d).swap(*this);
@@ -3739,7 +4600,11 @@ shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
template<class _Tp>
template<class _Yp, class _Dp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
-void
+typename enable_if
+<
+ is_convertible<_Yp*, _Tp*>::value,
+ void
+>::type
shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
{
shared_ptr(__p, __d, __a).swap(*this);
@@ -3749,7 +4614,11 @@ shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
template<class _Tp, class ..._Args>
inline _LIBCPP_INLINE_VISIBILITY
-shared_ptr<_Tp>
+typename enable_if
+<
+ !is_array<_Tp>::value,
+ shared_ptr<_Tp>
+>::type
make_shared(_Args&& ...__args)
{
return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
@@ -3757,7 +4626,11 @@ make_shared(_Args&& ...__args)
template<class _Tp, class _Alloc, class ..._Args>
inline _LIBCPP_INLINE_VISIBILITY
-shared_ptr<_Tp>
+typename enable_if
+<
+ !is_array<_Tp>::value,
+ shared_ptr<_Tp>
+>::type
allocate_shared(const _Alloc& __a, _Args&& ...__args)
{
return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
@@ -3852,7 +4725,128 @@ inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
{
- return __x.get() < __y.get();
+ typedef typename common_type<_Tp*, _Up*>::type _V;
+ return less<_V>()(__x.get(), __y.get());
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
+{
+ return __y < __x;
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
+{
+ return !(__y < __x);
+}
+
+template<class _Tp, class _Up>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
+{
+ return !(__x < __y);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
+{
+ return !__x;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
+{
+ return !__x;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
+{
+ return static_cast<bool>(__x);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
+{
+ return static_cast<bool>(__x);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
+{
+ return less<_Tp*>()(__x.get(), nullptr);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
+{
+ return less<_Tp*>()(nullptr, __x.get());
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
+{
+ return nullptr < __x;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
+{
+ return __x < nullptr;
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
+{
+ return !(nullptr < __x);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
+{
+ return !(__x < nullptr);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
+{
+ return !(__x < nullptr);
+}
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
+{
+ return !(nullptr < __x);
}
template<class _Tp>
@@ -3865,7 +4859,11 @@ swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
-shared_ptr<_Tp>
+typename enable_if
+<
+ !is_array<_Tp>::value && !is_array<_Up>::value,
+ shared_ptr<_Tp>
+>::type
static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
{
return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
@@ -3873,7 +4871,11 @@ static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
-shared_ptr<_Tp>
+typename enable_if
+<
+ !is_array<_Tp>::value && !is_array<_Up>::value,
+ shared_ptr<_Tp>
+>::type
dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
{
_Tp* __p = dynamic_cast<_Tp*>(__r.get());
@@ -3881,10 +4883,15 @@ dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
}
template<class _Tp, class _Up>
-shared_ptr<_Tp>
+typename enable_if
+<
+ is_array<_Tp>::value == is_array<_Up>::value,
+ shared_ptr<_Tp>
+>::type
const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
{
- return shared_ptr<_Tp>(__r, const_cast<_Tp*>(__r.get()));
+ typedef typename remove_extent<_Tp>::type _RTp;
+ return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
}
#ifndef _LIBCPP_NO_RTTI
@@ -3918,11 +4925,43 @@ public:
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
_NOEXCEPT;
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ weak_ptr(weak_ptr&& __r) _NOEXCEPT;
+ template<class _Yp> weak_ptr(weak_ptr<_Yp>&& __r,
+ typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
+ _NOEXCEPT;
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
~weak_ptr();
weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
- template<class _Yp> weak_ptr& operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
- template<class _Yp> weak_ptr& operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
+ template<class _Yp>
+ typename enable_if
+ <
+ is_convertible<_Yp*, element_type*>::value,
+ weak_ptr&
+ >::type
+ operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
+
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+ weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
+ template<class _Yp>
+ typename enable_if
+ <
+ is_convertible<_Yp*, element_type*>::value,
+ weak_ptr&
+ >::type
+ operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+ template<class _Yp>
+ typename enable_if
+ <
+ is_convertible<_Yp*, element_type*>::value,
+ weak_ptr&
+ >::type
+ operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
void swap(weak_ptr& __r) _NOEXCEPT;
void reset() _NOEXCEPT;
@@ -3991,6 +5030,33 @@ weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
__cntrl_->__add_weak();
}
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template<class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
+ : __ptr_(__r.__ptr_),
+ __cntrl_(__r.__cntrl_)
+{
+ __r.__ptr_ = 0;
+ __r.__cntrl_ = 0;
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
+ typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
+ _NOEXCEPT
+ : __ptr_(__r.__ptr_),
+ __cntrl_(__r.__cntrl_)
+{
+ __r.__ptr_ = 0;
+ __r.__cntrl_ = 0;
+}
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
template<class _Tp>
weak_ptr<_Tp>::~weak_ptr()
{
@@ -4010,17 +5076,52 @@ weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
template<class _Tp>
template<class _Yp>
inline _LIBCPP_INLINE_VISIBILITY
-weak_ptr<_Tp>&
+typename enable_if
+<
+ is_convertible<_Yp*, _Tp*>::value,
+ weak_ptr<_Tp>&
+>::type
weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
{
weak_ptr(__r).swap(*this);
return *this;
}
+#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
template<class _Tp>
-template<class _Yp>
inline _LIBCPP_INLINE_VISIBILITY
weak_ptr<_Tp>&
+weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
+{
+ weak_ptr(_VSTD::move(__r)).swap(*this);
+ return *this;
+}
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+ is_convertible<_Yp*, _Tp*>::value,
+ weak_ptr<_Tp>&
+>::type
+weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
+{
+ weak_ptr(_VSTD::move(__r)).swap(*this);
+ return *this;
+}
+
+#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template<class _Tp>
+template<class _Yp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+ is_convertible<_Yp*, _Tp*>::value,
+ weak_ptr<_Tp>&
+>::type
weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
{
weak_ptr(__r).swap(*this);
@@ -4149,10 +5250,10 @@ struct _LIBCPP_VISIBLE hash<shared_ptr<_Tp> >
}
};
-template<class _CharT, class _Traits, class _Y>
+template<class _CharT, class _Traits, class _Yp>
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
-operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Y> const& __p);
+operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
//enum class
struct _LIBCPP_VISIBLE pointer_safety
OpenPOWER on IntegriCloud