diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-09-16 22:26:52 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-09-16 22:26:52 +0000 |
commit | 854fa44b6f7a32ff94c2a705691da6d3b703574a (patch) | |
tree | aaccdba1a8c990ea730287a164e76e70733b424a /contrib/libc++/include/memory | |
parent | 0e1e5c22c20e636264ff1284083c6af7a1b282cb (diff) | |
parent | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (diff) | |
download | src-854fa44b6f7a32ff94c2a705691da6d3b703574a.tar.gz src-854fa44b6f7a32ff94c2a705691da6d3b703574a.zip |
Update libc++ to 3.7.0 release.
Notes
Notes:
svn path=/projects/clang370-import/; revision=287877
Diffstat (limited to 'contrib/libc++/include/memory')
-rw-r--r-- | contrib/libc++/include/memory | 227 |
1 files changed, 182 insertions, 45 deletions
diff --git a/contrib/libc++/include/memory b/contrib/libc++/include/memory index 662faa0a74ff..22311aaace92 100644 --- a/contrib/libc++/include/memory +++ b/contrib/libc++/include/memory @@ -75,6 +75,8 @@ struct allocator_traits | false_type propagate_on_container_move_assignment; typedef Alloc::propagate_on_container_swap | false_type propagate_on_container_swap; + typedef Alloc::is_always_equal + | is_empty is_always_equal; template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>; template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; @@ -615,6 +617,7 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space); #endif #include <__undef_min_max> +#include <__undef___deallocate> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -622,6 +625,18 @@ void* align(size_t alignment, size_t size, void*& ptr, size_t& space); _LIBCPP_BEGIN_NAMESPACE_STD +template <class _ValueType> +inline _LIBCPP_ALWAYS_INLINE +_ValueType __libcpp_relaxed_load(_ValueType const* __value) { +#if !defined(_LIBCPP_HAS_NO_THREADS) && \ + defined(__ATOMIC_RELAXED) && \ + (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407) + return __atomic_load_n(__value, __ATOMIC_RELAXED); +#else + return *__value; +#endif +} + // addressof moved to <__functional_base> template <class _Tp> class allocator; @@ -1143,6 +1158,29 @@ struct __propagate_on_container_swap<_Alloc, true> typedef typename _Alloc::propagate_on_container_swap type; }; +template <class _Tp> +struct __has_is_always_equal +{ +private: + struct __two {char __lx; char __lxx;}; + template <class _Up> static __two __test(...); + template <class _Up> static char __test(typename _Up::is_always_equal* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value> +struct __is_always_equal +{ + typedef typename _VSTD::is_empty<_Alloc>::type type; +}; + +template <class _Alloc> +struct __is_always_equal<_Alloc, true> +{ + typedef typename _Alloc::is_always_equal type; +}; + template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value> struct __has_rebind_other { @@ -1422,6 +1460,8 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits propagate_on_container_move_assignment; typedef typename __propagate_on_container_swap<allocator_type>::type propagate_on_container_swap; + typedef typename __is_always_equal<allocator_type>::type + is_always_equal; #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES template <class _Tp> using rebind_alloc = @@ -1520,8 +1560,42 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits __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; + if (_Np > 0) + { + _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp)); + __begin2 += _Np; + } + } + + template <class _Iter, class _Ptr> + _LIBCPP_INLINE_VISIBILITY + static + void + __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2) + { + for (; __begin1 != __end1; ++__begin1, (void) ++__begin2) + construct(__a, _VSTD::__to_raw_pointer(__begin2), *__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_range_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) + { + typedef typename remove_const<_Tp>::type _Vp; + ptrdiff_t _Np = __end1 - __begin1; + if (_Np > 0) + { + _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp)); + __begin2 += _Np; + } } template <class _Ptr> @@ -1551,7 +1625,8 @@ struct _LIBCPP_TYPE_VIS_ONLY allocator_traits { ptrdiff_t _Np = __end1 - __begin1; __end2 -= _Np; - _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp)); + if (_Np > 0) + _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp)); } private: @@ -1606,6 +1681,16 @@ private: {return __a;} }; +template <class _Traits, class _Tp> +struct __rebind_alloc_helper +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + typedef typename _Traits::template rebind_alloc<_Tp> type; +#else + typedef typename _Traits::template rebind_alloc<_Tp>::other type; +#endif +}; + // allocator template <class _Tp> @@ -1621,6 +1706,7 @@ public: typedef _Tp value_type; typedef true_type propagate_on_container_move_assignment; + typedef true_type is_always_equal; template <class _Up> struct rebind {typedef allocator<_Up> other;}; @@ -1713,6 +1799,7 @@ public: typedef const _Tp value_type; typedef true_type propagate_on_container_move_assignment; + typedef true_type is_always_equal; template <class _Up> struct rebind {typedef allocator<_Up> other;}; @@ -1816,6 +1903,9 @@ public: _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;} _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int) {raw_storage_iterator __t(*this); ++__x_; return __t;} +#if _LIBCPP_STD_VER >= 14 + _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; } +#endif }; template <class _Tp> @@ -1905,14 +1995,9 @@ 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 -#if __has_feature(is_final) - && !__is_final(_T1) -#endif - , + && !__libcpp_is_final<_T1>::value, bool = is_empty<_T2>::value -#if __has_feature(is_final) - && !__is_final(_T2) -#endif + && !__libcpp_is_final<_T2>::value > struct __libcpp_compressed_pair_switch; @@ -1950,11 +2035,11 @@ public: typedef const typename remove_reference<_T1>::type& _T1_const_reference; typedef const typename remove_reference<_T2>::type& _T2_const_reference; - _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} + _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_(), __second_() {} _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) - : __first_(_VSTD::forward<_T1_param>(__t1)) {} + : __first_(_VSTD::forward<_T1_param>(__t1)), __second_() {} _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2) - : __second_(_VSTD::forward<_T2_param>(__t2)) {} + : __first_(), __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)) {} @@ -2043,9 +2128,9 @@ public: typedef const _T1& _T1_const_reference; typedef const typename remove_reference<_T2>::type& _T2_const_reference; - _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} + _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __second_() {} _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1) - : _T1(_VSTD::forward<_T1_param>(__t1)) {} + : _T1(_VSTD::forward<_T1_param>(__t1)), __second_() {} _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) @@ -2133,11 +2218,11 @@ public: typedef const typename remove_reference<_T1>::type& _T1_const_reference; typedef const _T2& _T2_const_reference; - _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {} + _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_() {} _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) - : _T2(_VSTD::forward<_T2_param>(__t2)) {} + : _T2(_VSTD::forward<_T2_param>(__t2)), __first_() {} _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2) _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value && is_nothrow_move_constructible<_T2>::value) @@ -2890,8 +2975,8 @@ 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()); + typedef typename common_type<_P1, _P2>::type _Vp; + return less<_Vp>()(__x.get(), __y.get()); } template <class _T1, class _D1, class _T2, class _D2> @@ -3485,8 +3570,8 @@ uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r) try { #endif - for (; __f != __l; ++__f, ++__r) - ::new(&*__r) value_type(*__f); + for (; __f != __l; ++__f, (void) ++__r) + ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -3509,8 +3594,8 @@ uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r) try { #endif - for (; __n > 0; ++__f, ++__r, --__n) - ::new(&*__r) value_type(*__f); + for (; __n > 0; ++__f, (void) ++__r, (void) --__n) + ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -3534,7 +3619,7 @@ uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x) { #endif for (; __f != __l; ++__f) - ::new(&*__f) value_type(__x); + ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -3556,8 +3641,8 @@ uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x) try { #endif - for (; __n > 0; ++__f, --__n) - ::new(&*__f) value_type(__x); + for (; __n > 0; ++__f, (void) --__n) + ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x); #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) @@ -3599,7 +3684,9 @@ public: void __add_shared() _NOEXCEPT; bool __release_shared() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY - long use_count() const _NOEXCEPT {return __shared_owners_ + 1;} + long use_count() const _NOEXCEPT { + return __libcpp_relaxed_load(&__shared_owners_) + 1; + } }; class _LIBCPP_TYPE_VIS __shared_weak_count @@ -3677,11 +3764,11 @@ template <class _Tp, class _Dp, class _Alloc> void __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT { - typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _A; - typedef allocator_traits<_A> _ATraits; + typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al; + typedef allocator_traits<_Al> _ATraits; typedef pointer_traits<typename _ATraits::pointer> _PTraits; - _A __a(__data_.second()); + _Al __a(__data_.second()); __data_.second().~_Alloc(); __a.deallocate(_PTraits::pointer_to(*this), 1); } @@ -3746,10 +3833,10 @@ template <class _Tp, class _Alloc> void __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT { - typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _A; - typedef allocator_traits<_A> _ATraits; + typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al; + typedef allocator_traits<_Al> _ATraits; typedef pointer_traits<typename _ATraits::pointer> _PTraits; - _A __a(__data_.first()); + _Al __a(__data_.first()); __data_.first().~_Alloc(); __a.deallocate(_PTraits::pointer_to(*this), 1); } @@ -4001,11 +4088,15 @@ private: __enable_weak_this(const enable_shared_from_this<_Yp>* __e) _NOEXCEPT { if (__e) - __e->__weak_this_ = *this; + { + __e->__weak_this_.__ptr_ = const_cast<_Yp*>(static_cast<const _Yp*>(__e)); + __e->__weak_this_.__cntrl_ = __cntrl_; + __cntrl_->__add_weak(); + } } _LIBCPP_INLINE_VISIBILITY - void __enable_weak_this(const void*) _NOEXCEPT {} + void __enable_weak_this(const volatile void*) _NOEXCEPT {} template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr; template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr; @@ -4235,9 +4326,16 @@ shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, >::type) : __ptr_(__r.get()) { - typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>()); - __enable_weak_this(__r.get()); +#if _LIBCPP_STD_VER > 11 + if (__ptr_ == nullptr) + __cntrl_ = nullptr; + else +#endif + { + typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>()); + __enable_weak_this(__r.get()); + } __r.release(); } @@ -4257,11 +4355,18 @@ shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r, >::type) : __ptr_(__r.get()) { - typedef __shared_ptr_pointer<_Yp*, - reference_wrapper<typename remove_reference<_Dp>::type>, - allocator<_Yp> > _CntrlBlk; - __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>()); - __enable_weak_this(__r.get()); +#if _LIBCPP_STD_VER > 11 + if (__ptr_ == nullptr) + __cntrl_ = nullptr; + else +#endif + { + typedef __shared_ptr_pointer<_Yp*, + reference_wrapper<typename remove_reference<_Dp>::type>, + allocator<_Yp> > _CntrlBlk; + __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>()); + __enable_weak_this(__r.get()); + } __r.release(); } @@ -4745,8 +4850,8 @@ inline _LIBCPP_INLINE_VISIBILITY bool operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT { - typedef typename common_type<_Tp*, _Up*>::type _V; - return less<_V>()(__x.get(), __y.get()); + typedef typename common_type<_Tp*, _Up*>::type _Vp; + return less<_Vp>()(__x.get(), __y.get()); } template<class _Tp, class _Up> @@ -5438,6 +5543,38 @@ undeclare_reachable(_Tp* __p) _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space); +// --- Helper for container swap -- +template <typename _Alloc> +_LIBCPP_INLINE_VISIBILITY +void __swap_allocator(_Alloc & __a1, _Alloc & __a2) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT +#else + _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) +#endif +{ + __swap_allocator(__a1, __a2, + integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>()); +} + +template <typename _Alloc> +_LIBCPP_INLINE_VISIBILITY +void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type) +#if _LIBCPP_STD_VER >= 14 + _NOEXCEPT +#else + _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) +#endif +{ + using _VSTD::swap; + swap(__a1, __a2); +} + +template <typename _Alloc> +_LIBCPP_INLINE_VISIBILITY +void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {} + + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_MEMORY |