diff --git a/stl/inc/mdspan b/stl/inc/mdspan index e06ca1a4d2b..18bfbd32420 100644 --- a/stl/inc/mdspan +++ b/stl/inc/mdspan @@ -304,7 +304,7 @@ public: } } - template + template _NODISCARD constexpr bool _Contains_multidimensional_index( index_sequence<_Seq...>, _IndexTypes... _Indices) const noexcept { _STL_INTERNAL_STATIC_ASSERT((same_as<_IndexTypes, index_type> && ...)); @@ -321,7 +321,7 @@ inline constexpr size_t _Repeat_dynamic_extent = dynamic_extent; template requires (is_convertible_v<_Integrals, size_t> && ...) -extents(_Integrals...) -> extents...>; +explicit extents(_Integrals...) -> extents...>; template struct _Dextents_impl; @@ -532,7 +532,7 @@ public: template requires is_constructible_v constexpr explicit(extents_type::rank() > 0) - mapping(const layout_stride::template mapping<_OtherExtents>& _Other) noexcept // strengthened + mapping(const layout_stride::mapping<_OtherExtents>& _Other) noexcept // strengthened : _Base(_Other.extents()) { #if _CONTAINER_DEBUG_LEVEL > 0 if constexpr (extents_type::rank() > 0) { @@ -684,8 +684,7 @@ public: template requires is_constructible_v - constexpr explicit(extents_type::rank() > 0) - mapping(const layout_stride::template mapping<_OtherExtents>& _Other) noexcept + constexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::mapping<_OtherExtents>& _Other) noexcept : _Base(_Other.extents()) { #if _CONTAINER_DEBUG_LEVEL > 0 if constexpr (extents_type::rank() > 0) { @@ -1045,13 +1044,13 @@ struct default_accessor { requires is_convertible_v<_OtherElementType (*)[], element_type (*)[]> constexpr default_accessor(default_accessor<_OtherElementType>) noexcept {} - _NODISCARD constexpr data_handle_type offset(data_handle_type _Ptr, size_t _Idx) const noexcept { - return _Ptr + _Idx; - } - _NODISCARD constexpr reference access(data_handle_type _Ptr, size_t _Idx) const noexcept { return _Ptr[_Idx]; } + + _NODISCARD constexpr data_handle_type offset(data_handle_type _Ptr, size_t _Idx) const noexcept { + return _Ptr + _Idx; + } }; template @@ -1200,7 +1199,7 @@ public: _Ptr(_STD move(_Ptr_)) {} template - requires is_convertible_v<_OtherIndexType, index_type> + requires is_convertible_v && is_nothrow_constructible_v && (_Size == rank() || _Size == rank_dynamic()) && is_constructible_v && is_default_constructible_v @@ -1277,32 +1276,45 @@ public: noexcept(noexcept(_Access_impl(static_cast(_STD move(_Indices))...))) /* strengthened */ { return _Access_impl(static_cast(_STD move(_Indices))...); } -#endif // __cpp_multidimensional_subscript +private: + template + _NODISCARD constexpr reference _Multidimensional_subscript(span<_OtherIndexType, rank()> _Indices, + index_sequence<_Seq...>) const noexcept(noexcept(operator[](_STD as_const(_Indices[_Seq])...))) { + return operator[](_STD as_const(_Indices[_Seq])...); + } +#else // ^^^ defined(__cpp_multidimensional_subscript) / !defined(__cpp_multidimensional_subscript) vvv +private: + template + _NODISCARD constexpr reference _Multidimensional_access(_OtherIndexTypes... _Indices) const + noexcept(noexcept(_Access_impl(static_cast(_STD move(_Indices))...))) { + return _Access_impl(static_cast(_STD move(_Indices))...); + } + + template + _NODISCARD constexpr reference _Multidimensional_subscript(span<_OtherIndexType, rank()> _Indices, + index_sequence<_Seq...>) const noexcept(noexcept(_Multidimensional_access(_STD as_const(_Indices[_Seq])...))) { + return _Multidimensional_access(_STD as_const(_Indices[_Seq])...); + } +#endif // ^^^ !defined(__cpp_multidimensional_subscript) ^^^ + +public: template requires is_convertible_v && is_nothrow_constructible_v - _NODISCARD constexpr reference operator[](span<_OtherIndexType, rank()> _Indices) const { - return [&](index_sequence<_Seq...>) -> reference { -#ifdef __cpp_multidimensional_subscript // TRANSITION, P2128R6 - return operator[](_STD as_const(_Indices[_Seq])...); -#else // ^^^ defined(__cpp_multidimensional_subscript) / !defined(__cpp_multidimensional_subscript) vvv - return _Multidimensional_access(_STD as_const(_Indices[_Seq])...); -#endif // ^^^ !defined(__cpp_multidimensional_subscript) ^^^ - }(make_index_sequence{}); + _NODISCARD constexpr reference operator[](span<_OtherIndexType, rank()> _Indices) const + noexcept(noexcept(_Multidimensional_subscript(_Indices, make_index_sequence{}))) /* strengthened */ + { + return _Multidimensional_subscript(_Indices, make_index_sequence{}); } template requires is_convertible_v && is_nothrow_constructible_v - _NODISCARD constexpr reference operator[](const array<_OtherIndexType, rank()>& _Indices) const { - return [&](index_sequence<_Seq...>) -> reference { -#ifdef __cpp_multidimensional_subscript // TRANSITION, P2128R6 - return operator[](_Indices[_Seq]...); -#else // ^^^ defined(__cpp_multidimensional_subscript) / !defined(__cpp_multidimensional_subscript) vvv - return _Multidimensional_access(_Indices[_Seq]...); -#endif // ^^^ !defined(__cpp_multidimensional_subscript) ^^^ - }(make_index_sequence{}); + _NODISCARD constexpr reference operator[](const array<_OtherIndexType, rank()>& _Indices) const noexcept( + noexcept(_Multidimensional_subscript(span{_Indices}, make_index_sequence{}))) /* strengthened */ + { + return _Multidimensional_subscript(span{_Indices}, make_index_sequence{}); } _NODISCARD constexpr size_type size() const noexcept { @@ -1359,19 +1371,19 @@ public: return this->_Acc; } - _NODISCARD static constexpr bool is_always_unique() noexcept( - noexcept(mapping_type::is_always_unique())) /* strengthened */ { - return mapping_type::is_always_unique(); + _NODISCARD static constexpr bool is_always_unique() noexcept /* strengthened */ { + constexpr bool _Result = mapping_type::is_always_unique(); + return _Result; } - _NODISCARD static constexpr bool is_always_exhaustive() noexcept( - noexcept(mapping_type::is_always_exhaustive())) /* strengthened */ { - return mapping_type::is_always_exhaustive(); + _NODISCARD static constexpr bool is_always_exhaustive() noexcept /* strengthened */ { + constexpr bool _Result = mapping_type::is_always_exhaustive(); + return _Result; } - _NODISCARD static constexpr bool is_always_strided() noexcept( - noexcept(mapping_type::is_always_strided())) /* strengthened */ { - return mapping_type::is_always_strided(); + _NODISCARD static constexpr bool is_always_strided() noexcept /* strengthened */ { + constexpr bool _Result = mapping_type::is_always_strided(); + return _Result; } _NODISCARD constexpr bool is_unique() const noexcept(noexcept(this->_Map.is_unique())) /* strengthened */ { @@ -1392,16 +1404,9 @@ public: } private: -#ifndef __cpp_multidimensional_subscript // TRANSITION, P2128R6 - template - _NODISCARD constexpr reference _Multidimensional_access(_OtherIndexTypes... _Indices) const { - return _Access_impl(static_cast(_STD move(_Indices))...); - } -#endif // ^^^ !defined(__cpp_multidimensional_subscript) ^^^ - template _NODISCARD constexpr reference _Access_impl(_OtherIndexTypes... _Indices) const - noexcept(noexcept(this->_Acc.access(_Ptr, static_cast(this->_Map(_Indices...))))) /* strengthened */ { + noexcept(noexcept(this->_Acc.access(_Ptr, static_cast(this->_Map(_Indices...))))) { _STL_INTERNAL_STATIC_ASSERT((same_as<_OtherIndexTypes, index_type> && ...)); #if _CONTAINER_DEBUG_LEVEL > 0 _STL_VERIFY(this->_Map.extents()._Contains_multidimensional_index(make_index_sequence{}, _Indices...),