diff options
Diffstat (limited to 'libcxx/include/array')
-rw-r--r-- | libcxx/include/array | 87 |
1 files changed, 17 insertions, 70 deletions
diff --git a/libcxx/include/array b/libcxx/include/array index 068ab506a33..4eb2fe6fc62 100644 --- a/libcxx/include/array +++ b/libcxx/include/array @@ -118,57 +118,6 @@ template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexce _LIBCPP_BEGIN_NAMESPACE_STD template <class _Tp, size_t _Size> -struct __array_traits { - typedef _Tp _StorageT[_Size]; - - _LIBCPP_INLINE_VISIBILITY - static _LIBCPP_CONSTEXPR_AFTER_CXX14 typename remove_const<_Tp>::type* - __data(typename remove_const<_StorageT>::type& __store) { - return __store; - } - - _LIBCPP_INLINE_VISIBILITY - static _LIBCPP_CONSTEXPR_AFTER_CXX14 _Tp const* __data(const _StorageT& __store) { - return __store; - } - - _LIBCPP_INLINE_VISIBILITY - static void __swap(_StorageT& __lhs, _StorageT& __rhs) { - std::swap_ranges(__lhs, __lhs + _Size, __rhs); - } - - _LIBCPP_INLINE_VISIBILITY - static void __fill(_StorageT& __arr, _Tp const& __val) { - _VSTD::fill_n(__arr, _Size, __val); - } -}; - -template <class _Tp> -struct __array_traits<_Tp, 0> { - typedef typename aligned_storage<sizeof(_Tp), alignment_of<_Tp>::value>::type - _NonConstStorageT[1]; - typedef typename conditional<is_const<_Tp>::value, const _NonConstStorageT, - _NonConstStorageT>::type _StorageT; - typedef typename remove_const<_Tp>::type _NonConstTp; - - _LIBCPP_INLINE_VISIBILITY - static _NonConstTp* __data(_NonConstStorageT &__store) { - return reinterpret_cast<_NonConstTp*>(__store); - } - - _LIBCPP_INLINE_VISIBILITY - static const _Tp* __data(const _StorageT &__store) { - return reinterpret_cast<const _Tp*>(__store); - } - - _LIBCPP_INLINE_VISIBILITY - static void __swap(_StorageT&, _StorageT&) {} - - _LIBCPP_INLINE_VISIBILITY - static void __fill(_StorageT&, _Tp const&) {} -}; - -template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array { // types: @@ -185,33 +134,31 @@ struct _LIBCPP_TEMPLATE_VIS array typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; - typedef __array_traits<_Tp, _Size> _Traits; - typename _Traits::_StorageT __elems_; + value_type __elems_[_Size > 0 ? _Size : 1]; // No explicit construct/copy/destroy for aggregate type - _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) { - static_assert(_Size != 0 || !is_const<_Tp>::value, - "cannot fill zero-sized array of type 'const T'"); - _Traits::__fill(__elems_, __u); - } + _LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) + {_VSTD::fill_n(__elems_, _Size, __u);} + _LIBCPP_INLINE_VISIBILITY + void swap(array& __a) _NOEXCEPT_(_Size == 0 || __is_nothrow_swappable<_Tp>::value) + { __swap_dispatch((std::integral_constant<bool, _Size == 0>()), __a); } + + _LIBCPP_INLINE_VISIBILITY + void __swap_dispatch(std::true_type, array&) {} _LIBCPP_INLINE_VISIBILITY - void swap(array& __a) - _NOEXCEPT_(_Size == 0 || __is_nothrow_swappable<_Tp>::value) { - static_assert(_Size != 0 || !is_const<_Tp>::value, - "cannot swap zero-sized array of type 'const T'"); - _Traits::__swap(__elems_, __a.__elems_); - } + void __swap_dispatch(std::false_type, array& __a) + { _VSTD::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);} // iterators: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 - iterator begin() _NOEXCEPT {return iterator(data());} + iterator begin() _NOEXCEPT {return iterator(__elems_);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 - const_iterator begin() const _NOEXCEPT {return const_iterator(data());} + const_iterator begin() const _NOEXCEPT {return const_iterator(__elems_);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 - iterator end() _NOEXCEPT {return iterator(data() + _Size);} + iterator end() _NOEXCEPT {return iterator(__elems_ + _Size);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 - const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);} + const_iterator end() const _NOEXCEPT {return const_iterator(__elems_ + _Size);} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());} @@ -254,9 +201,9 @@ struct _LIBCPP_TEMPLATE_VIS array _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const {return __elems_[_Size > 0 ? _Size-1 : 0];} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 - value_type* data() _NOEXCEPT {return _Traits::__data(__elems_);} + value_type* data() _NOEXCEPT {return __elems_;} _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 - const value_type* data() const _NOEXCEPT {return _Traits::__data(__elems_);} + const value_type* data() const _NOEXCEPT {return __elems_;} }; template <class _Tp, size_t _Size> |