diff options
Diffstat (limited to 'include/deque')
| -rw-r--r-- | include/deque | 110 |
1 files changed, 77 insertions, 33 deletions
diff --git a/include/deque b/include/deque index 5e152e425d0b..c6fbd512a1c6 100644 --- a/include/deque +++ b/include/deque @@ -261,8 +261,21 @@ move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); +template <class _ValueType, class _DiffType> +struct __deque_block_size { + static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16; +}; + template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, - class _DiffType, _DiffType _BlockSize> + class _DiffType, _DiffType _BS = +#ifdef _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE +// Keep template parameter to avoid changing all template declarations thoughout +// this file. + 0 +#else + __deque_block_size<_ValueType, _DiffType>::value +#endif + > class _LIBCPP_TYPE_VIS_ONLY __deque_iterator { typedef _MapPointer __map_iterator; @@ -273,7 +286,7 @@ private: __map_iterator __m_iter_; pointer __ptr_; - static const difference_type __block_size = _BlockSize; + static const difference_type __block_size; public: typedef _ValueType value_type; typedef random_access_iterator_tag iterator_category; @@ -287,7 +300,7 @@ public: template <class _Pp, class _Rp, class _MP> _LIBCPP_INLINE_VISIBILITY - __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, __block_size>& __it, + __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, _BS>& __it, typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {} @@ -520,6 +533,12 @@ private: __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); }; +template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, + class _DiffType, _DiffType _BlockSize> +const _DiffType __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer, + _DiffType, _BlockSize>::__block_size = + __deque_block_size<_ValueType, _DiffType>::value; + // copy template <class _RAIter, @@ -532,10 +551,11 @@ copy(_RAIter __f, { typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size; while (__f != __l) { pointer __rb = __r.__ptr_; - pointer __re = *__r.__m_iter_ + _B2; + pointer __re = *__r.__m_iter_ + __block_size; difference_type __bs = __re - __rb; difference_type __n = __l - __f; _RAIter __m = __l; @@ -560,11 +580,12 @@ copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; - pointer __fe = *__f.__m_iter_ + _B1; + pointer __fe = *__f.__m_iter_ + __block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { @@ -587,11 +608,12 @@ copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; - pointer __fe = *__f.__m_iter_ + _B1; + pointer __fe = *__f.__m_iter_ + __block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { @@ -705,10 +727,11 @@ move(_RAIter __f, { typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size; while (__f != __l) { pointer __rb = __r.__ptr_; - pointer __re = *__r.__m_iter_ + _B2; + pointer __re = *__r.__m_iter_ + __block_size; difference_type __bs = __re - __rb; difference_type __n = __l - __f; _RAIter __m = __l; @@ -733,11 +756,12 @@ move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; - pointer __fe = *__f.__m_iter_ + _B1; + pointer __fe = *__f.__m_iter_ + __block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { @@ -760,11 +784,12 @@ move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; - pointer __fe = *__f.__m_iter_ + _B1; + pointer __fe = *__f.__m_iter_ + __block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { @@ -909,7 +934,7 @@ protected: typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; - static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16; + static const difference_type __block_size; typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator; typedef allocator_traits<__pointer_allocator> __map_traits; @@ -919,9 +944,9 @@ protected: typedef __split_buffer<pointer, __pointer_allocator> __map; typedef __deque_iterator<value_type, pointer, reference, __map_pointer, - difference_type, __block_size> iterator; + difference_type> iterator; typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer, - difference_type, __block_size> const_iterator; + difference_type> const_iterator; __map __map_; size_type __start_; @@ -939,8 +964,10 @@ protected: _LIBCPP_INLINE_VISIBILITY const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();} + _LIBCPP_INLINE_VISIBILITY __deque_base() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); + _LIBCPP_INLINE_VISIBILITY explicit __deque_base(const allocator_type& __a); public: ~__deque_base(); @@ -997,6 +1024,11 @@ private: }; template <class _Tp, class _Allocator> +const typename __deque_base<_Tp, _Allocator>::difference_type + __deque_base<_Tp, _Allocator>::__block_size = + __deque_block_size<value_type, difference_type>::value; + +template <class _Tp, class _Allocator> bool __deque_base<_Tp, _Allocator>::__invariants() const { @@ -1060,13 +1092,13 @@ __deque_base<_Tp, _Allocator>::end() const _NOEXCEPT } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline __deque_base<_Tp, _Allocator>::__deque_base() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) : __start_(0), __size_(0) {} template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline __deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a) : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {} @@ -1164,6 +1196,9 @@ public: typedef _Tp value_type; typedef _Allocator allocator_type; + static_assert((is_same<typename allocator_type::value_type, value_type>::value), + "Allocator::value_type must be same type as value_type"); + typedef __deque_base<value_type, allocator_type> __base; typedef typename __base::__alloc_traits __alloc_traits; @@ -1211,8 +1246,11 @@ public: #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value); + _LIBCPP_INLINE_VISIBILITY deque(deque&& __c, const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY deque& operator=(deque&& __c) _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<allocator_type>::value); @@ -1231,6 +1269,7 @@ public: void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());} #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT; // iterators: @@ -1283,13 +1322,21 @@ public: bool empty() const _NOEXCEPT {return __base::size() == 0;} // element access: + _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __i); + _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __i) const; + _LIBCPP_INLINE_VISIBILITY reference at(size_type __i); + _LIBCPP_INLINE_VISIBILITY const_reference at(size_type __i) const; + _LIBCPP_INLINE_VISIBILITY reference front(); + _LIBCPP_INLINE_VISIBILITY const_reference front() const; + _LIBCPP_INLINE_VISIBILITY reference back(); + _LIBCPP_INLINE_VISIBILITY const_reference back() const; // 23.2.2.3 modifiers: @@ -1328,6 +1375,7 @@ public: iterator erase(const_iterator __p); iterator erase(const_iterator __f, const_iterator __l); + _LIBCPP_INLINE_VISIBILITY void swap(deque& __c) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT; @@ -1335,6 +1383,7 @@ public: _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value); #endif + _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY @@ -1507,7 +1556,7 @@ deque<_Tp, _Allocator>::operator=(const deque& __c) #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline deque<_Tp, _Allocator>::deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) : __base(_VSTD::move(__c)) @@ -1515,7 +1564,7 @@ deque<_Tp, _Allocator>::deque(deque&& __c) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a) : __base(_VSTD::move(__c), __a) { @@ -1527,7 +1576,7 @@ deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline deque<_Tp, _Allocator>& deque<_Tp, _Allocator>::operator=(deque&& __c) _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && @@ -1611,7 +1660,7 @@ deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline _Allocator deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT { @@ -1670,7 +1719,7 @@ deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::operator[](size_type __i) { @@ -1679,7 +1728,7 @@ deque<_Tp, _Allocator>::operator[](size_type __i) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::operator[](size_type __i) const { @@ -1688,7 +1737,7 @@ deque<_Tp, _Allocator>::operator[](size_type __i) const } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::at(size_type __i) { @@ -1699,7 +1748,7 @@ deque<_Tp, _Allocator>::at(size_type __i) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::at(size_type __i) const { @@ -1710,7 +1759,7 @@ deque<_Tp, _Allocator>::at(size_type __i) const } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::front() { @@ -1719,7 +1768,7 @@ deque<_Tp, _Allocator>::front() } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::front() const { @@ -1728,7 +1777,7 @@ deque<_Tp, _Allocator>::front() const } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::back() { @@ -1737,7 +1786,7 @@ deque<_Tp, _Allocator>::back() } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::back() const { @@ -2029,7 +2078,6 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_ty if (__n > __front_spare()) __add_front_capacity(__n - __front_spare()); // __n <= __front_spare() - size_type __old_n = __n; iterator __old_begin = __base::begin(); iterator __i = __old_begin; if (__n > __pos) @@ -2054,7 +2102,6 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_ty if (__n > __back_capacity) __add_back_capacity(__n - __back_capacity); // __n <= __back_capacity - size_type __old_n = __n; iterator __old_end = __base::end(); iterator __i = __old_end; size_type __de = __base::size() - __pos; @@ -2119,7 +2166,6 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l, if (__n > __front_spare()) __add_front_capacity(__n - __front_spare()); // __n <= __front_spare() - size_type __old_n = __n; iterator __old_begin = __base::begin(); iterator __i = __old_begin; _BiIter __m = __f; @@ -2150,7 +2196,6 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l, if (__n > __back_capacity) __add_back_capacity(__n - __back_capacity); // __n <= __back_capacity - size_type __old_n = __n; iterator __old_end = __base::end(); iterator __i = __old_end; _BiIter __m = __l; @@ -2685,7 +2730,6 @@ template <class _Tp, class _Allocator> typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::erase(const_iterator __f) { - difference_type __n = 1; iterator __b = __base::begin(); difference_type __pos = __f - __b; iterator __p = __b + __pos; @@ -2781,7 +2825,7 @@ deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline void deque<_Tp, _Allocator>::swap(deque& __c) #if _LIBCPP_STD_VER >= 14 @@ -2795,7 +2839,7 @@ deque<_Tp, _Allocator>::swap(deque& __c) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline void deque<_Tp, _Allocator>::clear() _NOEXCEPT { |
