diff --git a/include/array_view b/include/array_view index 270af5c5418..0c5ae8ac0f7 100644 --- a/include/array_view +++ b/include/array_view @@ -22,14 +22,6 @@ namespace std return data[offset]; \ } -template struct decompose {}; - -template -struct decompose<__indices, ArrayType> { - static inline const bounds call() { - return move(bounds{extent::value...}); - } -}; template static inline offset get_stride(const bounds& bnd) @@ -42,7 +34,7 @@ static inline offset get_stride(const bounds& bnd) } -template class strided_array_view; +template class strided_array_view; template struct __has_data @@ -67,17 +59,17 @@ public: }; template -struct __is_container +struct __is_viewable { using _T = typename std::remove_reference::type; static const bool value = __has_size<_T>::value && __has_data<_T>::value; }; -template +template class array_view { public: - static constexpr int rank = Rank; - using offset_type = offset; + static constexpr size_t rank = Rank; + using offset_type = offset; using bounds_type = bounds; using size_type = size_t; using value_type = T; @@ -86,10 +78,10 @@ public: array_view() noexcept : data_(nullptr), bnd_(), stride_() {} - template ::value + __is_viewable::value >::type > array_view(Viewable&& vw) : data_(vw.data()), bnd_(vw.size()), stride_() { @@ -99,7 +91,7 @@ public: typename remove_cv::type>::value, "illegal Viewable"); } - template ::type, pointer>::value && @@ -109,23 +101,12 @@ public: array_view(const array_view& rhs) noexcept : data_(rhs.data()), bnd_(rhs.size()), stride_(1) {} - template ::type>::type, - pointer - >::value && - is_same::type>::type, - typename remove_cv::type - >::value && - std::rank::value == N - >::type + template ::type > - array_view(ArrayType& arr) noexcept - : data_(reinterpret_cast(arr)), - bnd_(decompose::type, ArrayType>::call()), stride_(get_stride(bnd_)) {} + array_view(value_type (&arr)[Extent]) noexcept + : data_(arr), bnd_(Extent), stride_(get_stride(bnd_)) {} template ::type, pointer>::value && - is_same< - typename remove_cv::type, - typename remove_cv::type - >::value - >::type - > - array_view& operator=(const array_view& rhs) noexcept { - data_ = rhs.data_; - bnd_ = rhs.bnd_; - stride_ = rhs.stride_; - } - bounds_type bounds() const noexcept { return bnd_; } size_type size() const noexcept { return bnd_.size(); } offset_type stride() const noexcept { return stride_; } @@ -175,7 +141,7 @@ public: } // [arrayview.subview], array_view slicing and sectioning - template 1)>::type> + template 1)>::type> array_view operator[](ptrdiff_t slice) const { assert(slice < bnd_[0]); @@ -190,7 +156,7 @@ public: for (auto i = 0; i < Rank; ++i) assert(range[i] >= section_bnd[i]); ptrdiff_t offset = 0; - for (int i = 0; i < Rank; ++i) + for (auto i = 0; i < Rank; ++i) offset += origin[i] * stride_[i]; return strided_array_view(data_ + offset, section_bnd, stride_); } @@ -204,11 +170,11 @@ private: offset_type stride_; }; -template +template class strided_array_view { public: // constants and types - static constexpr int rank = Rank; + static constexpr size_t rank = Rank; using offset_type = offset; using bounds_type = bounds; using size_type = size_t; @@ -245,21 +211,6 @@ public: strided_array_view(pointer ptr, bounds_type bounds, offset_type stride) : data_(ptr), bnd_(bounds), stride_(stride) {} - template ::type, pointer>::value && - is_same< - typename remove_cv::type, - typename remove_cv::type - >::value - >::type - > - strided_array_view& operator=(const strided_array_view& rhs) noexcept { - data_ = rhs.data_; - bnd_ = rhs.bnd_; - stride_ = rhs.stride_; - } - bounds_type bounds() const noexcept { return bnd_; } size_type size() const noexcept { return bnd_.size(); } offset_type stride() const noexcept { return stride_; } @@ -269,7 +220,7 @@ public: VIEW_ACCESS(data_, idx, stride(), Rank); } - template 1)>::type> + template 1)>::type> strided_array_view operator[](ptrdiff_t slice) const { assert(slice < bnd_[0]); @@ -287,7 +238,7 @@ public: for (auto i = 0; i < Rank; ++i) assert(range[i] >= section_bnd[i]); ptrdiff_t offset = 0; - for (int i = 0; i < Rank; ++i) + for (auto i = 0; i < Rank; ++i) offset += origin[i] * stride_[i]; return strided_array_view(data_ + offset, section_bnd, stride_); } @@ -296,7 +247,7 @@ public: private: static_assert(Rank >= 1, "Rank should be greater than or equal to 1"); - template friend class strided_array_view; + template friend class strided_array_view; pointer data_; // exposition only bounds_type bnd_; offset_type stride_; diff --git a/stl-test/Tests/array_view/array_view/array_view.cpp b/stl-test/Tests/array_view/array_view/array_view.cpp index 13afbb79abc..d97f1c29591 100644 --- a/stl-test/Tests/array_view/array_view/array_view.cpp +++ b/stl-test/Tests/array_view/array_view/array_view.cpp @@ -28,6 +28,13 @@ int main() for (int i = 0; i < 120; i++) ret &= bv.data()[i] == i; } + { + char a[12] {'H', 'i'}; + auto av = std::array_view{a}; + ret &= av.bounds() == std::bounds<1>{12}; + ret &= av[{0}] == 'H'; + ret &= av[{1}] == 'i'; + } { std::vector vec(120); for (int i = 0; i < 120; i++)