aboutsummaryrefslogtreecommitdiff
path: root/system/include/libcxx/memory
diff options
context:
space:
mode:
Diffstat (limited to 'system/include/libcxx/memory')
-rw-r--r--system/include/libcxx/memory1702
1 files changed, 1473 insertions, 229 deletions
diff --git a/system/include/libcxx/memory b/system/include/libcxx/memory
index d272c08c..4e1f7046 100644
--- a/system/include/libcxx/memory
+++ b/system/include/libcxx/memory
@@ -596,19 +596,23 @@ 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
-#pragma GCC system_header
-
-_LIBCPP_BEGIN_NAMESPACE_STD
+#if __has_feature(cxx_atomic)
+# include <atomic>
+#endif
-// allocator_arg_t
+#include <__undef_min_max>
-struct _LIBCPP_VISIBLE allocator_arg_t { };
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
-extern const allocator_arg_t allocator_arg;
+_LIBCPP_BEGIN_NAMESPACE_STD
// addressof
@@ -673,13 +677,24 @@ 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>
struct __has_element_type
{
private:
- struct __two {char _; char __;};
+ struct __two {char __lx; char __lxx;};
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename _Up::element_type* = 0);
public:
@@ -767,7 +782,7 @@ template <class _Tp>
struct __has_difference_type
{
private:
- struct __two {char _; char __;};
+ struct __two {char __lx; char __lxx;};
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename _Up::difference_type* = 0);
public:
@@ -790,7 +805,7 @@ template <class _Tp, class _Up>
struct __has_rebind
{
private:
- struct __two {char _; char __;};
+ struct __two {char __lx; char __lxx;};
template <class _Xp> static __two __test(...);
template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
public:
@@ -983,7 +998,7 @@ template <class _Tp>
struct __has_const_pointer
{
private:
- struct __two {char _; char __;};
+ struct __two {char __lx; char __lxx;};
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename _Up::const_pointer* = 0);
public:
@@ -1010,7 +1025,7 @@ template <class _Tp>
struct __has_void_pointer
{
private:
- struct __two {char _; char __;};
+ struct __two {char __lx; char __lxx;};
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename _Up::void_pointer* = 0);
public:
@@ -1037,7 +1052,7 @@ template <class _Tp>
struct __has_const_void_pointer
{
private:
- struct __two {char _; char __;};
+ struct __two {char __lx; char __lxx;};
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
public:
@@ -1060,10 +1075,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;
}
@@ -1080,7 +1095,7 @@ template <class _Tp>
struct __has_size_type
{
private:
- struct __two {char _; char __;};
+ struct __two {char __lx; char __lxx;};
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename _Up::size_type* = 0);
public:
@@ -1103,7 +1118,7 @@ template <class _Tp>
struct __has_propagate_on_container_copy_assignment
{
private:
- struct __two {char _; char __;};
+ struct __two {char __lx; char __lxx;};
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
public:
@@ -1126,7 +1141,7 @@ template <class _Tp>
struct __has_propagate_on_container_move_assignment
{
private:
- struct __two {char _; char __;};
+ struct __two {char __lx; char __lxx;};
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
public:
@@ -1149,7 +1164,7 @@ template <class _Tp>
struct __has_propagate_on_container_swap
{
private:
- struct __two {char _; char __;};
+ struct __two {char __lx; char __lxx;};
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
public:
@@ -1172,7 +1187,7 @@ template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
struct __has_rebind_other
{
private:
- struct __two {char _; char __;};
+ struct __two {char __lx; char __lxx;};
template <class _Xp> static __two __test(...);
template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
public:
@@ -1385,6 +1400,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>
@@ -1514,6 +1537,63 @@ 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-1), _VSTD::move_if_noexcept(*--__end1));
+ --__end2;
+ }
+ }
+
+ 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
@@ -1522,7 +1602,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
@@ -1566,58 +1646,6 @@ private:
{return __a;}
};
-// uses_allocator
-
-template <class _Tp>
-struct __has_allocator_type
-{
-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>
-{
-};
-
-#ifndef _LIBCPP_HAS_NO_VARIADICS
-
-// uses-allocator construction
-
-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;
-};
-
-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>
@@ -1664,38 +1692,110 @@ public:
::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
+ void
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
+ void
construct(pointer __p, const _A0& __a0)
{
::new((void*)__p) _Tp(__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 _LIBCPP_VISIBLE allocator<const _Tp>
+{
+public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef const _Tp* pointer;
+ typedef const _Tp* const_pointer;
+ typedef const _Tp& reference;
+ typedef const _Tp& const_reference;
+ typedef _Tp value_type;
+
+ typedef true_type propagate_on_container_move_assignment;
+
+ template <class _Up> struct rebind {typedef allocator<_Up> other;};
+
+ _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
+ template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
+ _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)
+ void
+ construct(pointer __p, _A0& __a0)
{
- ::new((void*)__p) _Tp(_VSTD::move(__a0));
+ ::new((void*)__p) _Tp(__a0);
+ }
+ template <class _A0>
+ _LIBCPP_INLINE_VISIBILITY
+ void
+ construct(pointer __p, const _A0& __a0)
+ {
+ ::new((void*)__p) _Tp(__a0);
}
# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
template <class _A0, class _A1>
@@ -1844,8 +1944,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>
@@ -1883,9 +1991,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)) {}
@@ -1928,6 +2036,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
@@ -1965,9 +2088,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)) {}
@@ -2008,6 +2131,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
@@ -2089,6 +2227,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
@@ -2167,6 +2321,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
@@ -2177,7 +2346,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)
{
@@ -2200,9 +2369,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)) {}
@@ -2239,6 +2408,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
@@ -2263,10 +2446,39 @@ 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
{
- _LIBCPP_INLINE_VISIBILITY default_delete() _NOEXCEPT {}
+#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
+#else
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
+#endif
template <class _Up>
_LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
@@ -2280,13 +2492,23 @@ struct _LIBCPP_VISIBLE default_delete
template <class _Tp>
struct _LIBCPP_VISIBLE default_delete<_Tp[]>
{
- _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
+public:
+#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
+#else
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
+#endif
+ 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> >
@@ -2299,14 +2521,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>&);
@@ -2320,13 +2535,13 @@ private:
typedef typename remove_reference<deleter_type>::type& _Dp_reference;
typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
public:
- _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
: __ptr_(pointer())
{
static_assert(!is_pointer<deleter_type>::value,
"unique_ptr constructed with null function pointer deleter");
}
- _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
: __ptr_(pointer())
{
static_assert(!is_pointer<deleter_type>::value,
@@ -2393,7 +2608,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
@@ -2450,9 +2667,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
{
@@ -2483,10 +2700,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>&);
@@ -2500,33 +2714,33 @@ private:
typedef typename remove_reference<deleter_type>::type& _Dp_reference;
typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
public:
- _LIBCPP_INLINE_VISIBILITY unique_ptr() _NOEXCEPT
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
: __ptr_(pointer())
{
static_assert(!is_pointer<deleter_type>::value,
"unique_ptr constructed with null function pointer deleter");
}
- _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t) _NOEXCEPT
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
: __ptr_(pointer())
{
static_assert(!is_pointer<deleter_type>::value,
"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)
@@ -2540,11 +2754,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))
{
@@ -2567,6 +2780,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)
@@ -2613,8 +2860,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
{
@@ -2624,10 +2872,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;
@@ -2696,7 +2944,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
@@ -2713,8 +2967,431 @@ 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) _NOEXCEPT
+{
+ return !__x;
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
+{
+ return !__x;
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
+{
+ return static_cast<bool>(__x);
+}
+
+template <class _T1, class _D1>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
+{
+ 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);
+}
+
+#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
+template <class _Tp, class _Dp>
+inline _LIBCPP_INLINE_VISIBILITY
+unique_ptr<_Tp, _Dp>
+move(unique_ptr<_Tp, _Dp>& __t)
+{
+ return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
+}
+
+#endif
+
template <class _Tp> struct hash;
+// 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
+ {
+ 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 unary_function<_Tp*, size_t>
@@ -2722,8 +3399,13 @@ struct _LIBCPP_VISIBLE hash<_Tp*>
_LIBCPP_INLINE_VISIBILITY
size_t operator()(_Tp* __v) const _NOEXCEPT
{
- const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
- return *__p;
+ union
+ {
+ _Tp* __t;
+ size_t __a;
+ } __u;
+ __u.__t = __v;
+ return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
}
};
@@ -2802,12 +3484,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;
}
@@ -2815,12 +3508,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;
}
@@ -2828,24 +3532,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;
}
@@ -2857,7 +3583,7 @@ public:
virtual const char* what() const _NOEXCEPT;
};
-template<class _Tp> class weak_ptr;
+template<class _Tp> class _LIBCPP_VISIBLE weak_ptr;
class __shared_count
{
@@ -2903,7 +3629,11 @@ public:
long use_count() const _NOEXCEPT {return __shared_count::use_count();}
__shared_weak_count* lock() _NOEXCEPT;
-#ifndef _LIBCPP_NO_RTTI
+ // Define the function out only if we build static libc++ without RTTI.
+ // Otherwise we may break clients who need to compile their projects with
+ // -fno-rtti and yet link against a libc++.dylib compiled
+ // without -fno-rtti.
+#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
#endif
private:
@@ -2972,7 +3702,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
@@ -3021,7 +3752,7 @@ __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
__a.deallocate(this, 1);
}
-template<class _Tp> class enable_shared_from_this;
+template<class _Tp> class _LIBCPP_VISIBLE enable_shared_from_this;
template<class _Tp>
class _LIBCPP_VISIBLE shared_ptr
@@ -3034,11 +3765,29 @@ private:
struct __nat {int __for_bool_;};
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);
+ _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
+ _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
+ 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 +3805,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,15 +3946,19 @@ 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_;}
+ _LIBCPP_INLINE_VISIBILITY
+ bool
+ __owner_equivalent(const shared_ptr& __p) const
+ {return __cntrl_ == __p.__cntrl_;}
#ifndef _LIBCPP_NO_RTTI
template <class _Dp>
@@ -3193,6 +4030,7 @@ private:
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
: __ptr_(0),
__cntrl_(0)
@@ -3201,6 +4039,7 @@ shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
: __ptr_(0),
__cntrl_(0)
@@ -3208,7 +4047,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 +4059,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 +4102,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 +4216,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 +4231,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 +4247,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 +4468,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 +4493,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 +4507,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 +4522,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 +4539,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 +4554,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 +4588,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 +4601,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 +4614,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 +4628,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 +4640,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 +4739,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 +4873,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 +4885,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 +4897,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
@@ -3909,7 +4930,7 @@ private:
__shared_weak_count* __cntrl_;
public:
- weak_ptr() _NOEXCEPT;
+ _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
template<class _Yp> weak_ptr(shared_ptr<_Yp> const& __r,
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
_NOEXCEPT;
@@ -3918,11 +4939,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;
@@ -3949,6 +5002,7 @@ public:
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR
weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
: __ptr_(0),
__cntrl_(0)
@@ -3991,6 +5045,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 +5091,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);
@@ -4117,7 +5233,7 @@ class _LIBCPP_VISIBLE enable_shared_from_this
{
mutable weak_ptr<_Tp> __weak_this_;
protected:
- _LIBCPP_INLINE_VISIBILITY
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
enable_shared_from_this() _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY
enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
@@ -4149,25 +5265,153 @@ 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);
+
+#if __has_feature(cxx_atomic)
+
+class __sp_mut
+{
+ void* __lx;
+public:
+ void lock() _NOEXCEPT;
+ void unlock() _NOEXCEPT;
+
+private:
+ _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
+ __sp_mut(const __sp_mut&);
+ __sp_mut& operator=(const __sp_mut&);
+
+ friend _LIBCPP_VISIBLE __sp_mut& __get_sp_mut(const void*);
+};
+
+_LIBCPP_VISIBLE __sp_mut& __get_sp_mut(const void*);
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+atomic_is_lock_free(const shared_ptr<_Tp>*)
+{
+ return false;
+}
+
+template <class _Tp>
+shared_ptr<_Tp>
+atomic_load(const shared_ptr<_Tp>* __p)
+{
+ __sp_mut& __m = __get_sp_mut(__p);
+ __m.lock();
+ shared_ptr<_Tp> __q = *__p;
+ __m.unlock();
+ return __q;
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
+{
+ return atomic_load(__p);
+}
+
+template <class _Tp>
+void
+atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
+{
+ __sp_mut& __m = __get_sp_mut(__p);
+ __m.lock();
+ __p->swap(__r);
+ __m.unlock();
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+void
+atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
+{
+ atomic_store(__p, __r);
+}
+
+template <class _Tp>
+shared_ptr<_Tp>
+atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
+{
+ __sp_mut& __m = __get_sp_mut(__p);
+ __m.lock();
+ __p->swap(__r);
+ __m.unlock();
+ return __r;
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+shared_ptr<_Tp>
+atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
+{
+ return atomic_exchange(__p, __r);
+}
+
+template <class _Tp>
+bool
+atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
+{
+ __sp_mut& __m = __get_sp_mut(__p);
+ __m.lock();
+ if (__p->__owner_equivalent(*__v))
+ {
+ *__p = __w;
+ __m.unlock();
+ return true;
+ }
+ *__v = *__p;
+ __m.unlock();
+ return false;
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
+{
+ return atomic_compare_exchange_strong(__p, __v, __w);
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
+ shared_ptr<_Tp> __w, memory_order, memory_order)
+{
+ return atomic_compare_exchange_strong(__p, __v, __w);
+}
+
+template <class _Tp>
+inline _LIBCPP_INLINE_VISIBILITY
+bool
+atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
+ shared_ptr<_Tp> __w, memory_order, memory_order)
+{
+ return atomic_compare_exchange_weak(__p, __v, __w);
+}
+
+#endif // __has_feature(cxx_atomic)
//enum class
struct _LIBCPP_VISIBLE pointer_safety
{
- enum _
+ enum __lx
{
relaxed,
preferred,
strict
};
- _ __v_;
+ __lx __v_;
_LIBCPP_INLINE_VISIBILITY
- pointer_safety(_ __v) : __v_(__v) {}
+ pointer_safety(__lx __v) : __v_(__v) {}
_LIBCPP_INLINE_VISIBILITY
operator int() const {return __v_;}
};