Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 49 additions & 44 deletions stl/inc/mdspan
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public:
}
}

template <class... _IndexTypes, size_t... _Seq>
template <size_t... _Seq, class... _IndexTypes>
_NODISCARD constexpr bool _Contains_multidimensional_index(
index_sequence<_Seq...>, _IndexTypes... _Indices) const noexcept {
_STL_INTERNAL_STATIC_ASSERT((same_as<_IndexTypes, index_type> && ...));
Expand All @@ -321,7 +321,7 @@ inline constexpr size_t _Repeat_dynamic_extent = dynamic_extent;

template <class... _Integrals>
requires (is_convertible_v<_Integrals, size_t> && ...)
extents(_Integrals...) -> extents<size_t, _Repeat_dynamic_extent<_Integrals>...>;
explicit extents(_Integrals...) -> extents<size_t, _Repeat_dynamic_extent<_Integrals>...>;

template <class _IndexType, class _Indices>
struct _Dextents_impl;
Expand Down Expand Up @@ -532,7 +532,7 @@ public:
template <class _OtherExtents>
requires is_constructible_v<extents_type, _OtherExtents>
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) {
Expand Down Expand Up @@ -684,8 +684,7 @@ public:

template <class _OtherExtents>
requires is_constructible_v<extents_type, _OtherExtents>
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) {
Expand Down Expand Up @@ -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 <class _LayoutPolicy, class _Extents>
Expand Down Expand Up @@ -1200,7 +1199,7 @@ public:
_Ptr(_STD move(_Ptr_)) {}

template <class _OtherIndexType, size_t _Size>
requires is_convertible_v<_OtherIndexType, index_type>
requires is_convertible_v<const _OtherIndexType&, index_type>
&& is_nothrow_constructible_v<index_type, const _OtherIndexType&>
&& (_Size == rank() || _Size == rank_dynamic())
&& is_constructible_v<mapping_type, extents_type> && is_default_constructible_v<accessor_type>
Expand Down Expand Up @@ -1277,32 +1276,45 @@ public:
noexcept(noexcept(_Access_impl(static_cast<index_type>(_STD move(_Indices))...))) /* strengthened */ {
return _Access_impl(static_cast<index_type>(_STD move(_Indices))...);
}
#endif // __cpp_multidimensional_subscript

private:
template <class _OtherIndexType, size_t... _Seq>
_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 <class... _OtherIndexTypes>
_NODISCARD constexpr reference _Multidimensional_access(_OtherIndexTypes... _Indices) const
noexcept(noexcept(_Access_impl(static_cast<index_type>(_STD move(_Indices))...))) {
return _Access_impl(static_cast<index_type>(_STD move(_Indices))...);
}

template <class _OtherIndexType, size_t... _Seq>
_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 <class _OtherIndexType>
requires is_convertible_v<const _OtherIndexType&, index_type>
&& is_nothrow_constructible_v<index_type, const _OtherIndexType&>
_NODISCARD constexpr reference operator[](span<_OtherIndexType, rank()> _Indices) const {
return [&]<size_t... _Seq>(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<rank()>{});
_NODISCARD constexpr reference operator[](span<_OtherIndexType, rank()> _Indices) const
noexcept(noexcept(_Multidimensional_subscript(_Indices, make_index_sequence<rank()>{}))) /* strengthened */
{
return _Multidimensional_subscript(_Indices, make_index_sequence<rank()>{});
}

template <class _OtherIndexType>
requires is_convertible_v<const _OtherIndexType&, index_type>
&& is_nothrow_constructible_v<index_type, const _OtherIndexType&>
_NODISCARD constexpr reference operator[](const array<_OtherIndexType, rank()>& _Indices) const {
return [&]<size_t... _Seq>(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<rank()>{});
_NODISCARD constexpr reference operator[](const array<_OtherIndexType, rank()>& _Indices) const noexcept(
noexcept(_Multidimensional_subscript(span{_Indices}, make_index_sequence<rank()>{}))) /* strengthened */
{
return _Multidimensional_subscript(span{_Indices}, make_index_sequence<rank()>{});
}

_NODISCARD constexpr size_type size() const noexcept {
Expand Down Expand Up @@ -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 */ {
Expand All @@ -1392,16 +1404,9 @@ public:
}

private:
#ifndef __cpp_multidimensional_subscript // TRANSITION, P2128R6
template <class... _OtherIndexTypes>
_NODISCARD constexpr reference _Multidimensional_access(_OtherIndexTypes... _Indices) const {
return _Access_impl(static_cast<index_type>(_STD move(_Indices))...);
}
#endif // ^^^ !defined(__cpp_multidimensional_subscript) ^^^

template <class... _OtherIndexTypes>
_NODISCARD constexpr reference _Access_impl(_OtherIndexTypes... _Indices) const
noexcept(noexcept(this->_Acc.access(_Ptr, static_cast<size_t>(this->_Map(_Indices...))))) /* strengthened */ {
noexcept(noexcept(this->_Acc.access(_Ptr, static_cast<size_t>(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<rank()>{}, _Indices...),
Expand Down