Skip to content

Commit

Permalink
Revert "EBO for layout_stride"
Browse files Browse the repository at this point in the history
This reverts commit 731ff98.
  • Loading branch information
JMazurkiewicz committed Jul 5, 2023
1 parent 731ff98 commit 73e7ba4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
53 changes: 24 additions & 29 deletions stl/inc/mdspan
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ struct _Maybe_fully_static_extents<_Extents> {
template <class _OtherExtents>
constexpr explicit _Maybe_fully_static_extents([[maybe_unused]] const _OtherExtents& _Exts_) {
#if _CONTAINER_DEBUG_LEVEL > 0
(void) _Extents{_Exts_}; // NB: temporary created for preconditions check
(void) _Extents(_Exts_); // NB: temporary created for preconditions check
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
};
Expand All @@ -471,7 +471,7 @@ public:
using layout_type = layout_left;

private:
using _Base = _Maybe_fully_static_extents<extents_type>;
using _Base = _Maybe_fully_static_extents<_Extents>;

static_assert(_Is_extents<extents_type>,
"Extents must be a specialization of std::extents (N4950 [mdspan.layout.left.overview]/2).");
Expand Down Expand Up @@ -623,7 +623,7 @@ public:
using layout_type = layout_right;

private:
using _Base = _Maybe_fully_static_extents<extents_type>;
using _Base = _Maybe_fully_static_extents<_Extents>;

static_assert(_Is_extents<extents_type>,
"Extents must be a specialization of std::extents (N4950 [mdspan.layout.right.overview]/2).");
Expand Down Expand Up @@ -777,42 +777,35 @@ concept _Layout_mapping_alike = requires {
};

template <class _Extents>
class layout_stride::mapping : private _Maybe_fully_static_extents<_Extents>,
private _Maybe_empty_array<typename _Extents::index_type, _Extents::rank()> {
class layout_stride::mapping {
public:
using extents_type = _Extents;
using index_type = extents_type::index_type;
using size_type = extents_type::size_type;
using rank_type = extents_type::rank_type;
using layout_type = layout_stride;

private:
using _Extents_base = _Maybe_fully_static_extents<extents_type>;
using _Strides_base = _Maybe_empty_array<index_type, _Extents::rank()>;

static_assert(_Is_extents<extents_type>,
"Extents must be a specialization of std::extents (N4950 [mdspan.layout.stride.overview]/2).");
static_assert(
extents_type::rank_dynamic() != 0 || extents_type::_Is_static_multidim_index_space_size_representable(),
"If Extents::rank_dynamic() == 0 is true, then the size of the multidimensional index space Extents() must be "
"representable as a value of type typename Extents::index_type (N4950 [mdspan.layout.stride.overview]/4).");

public:
constexpr mapping() noexcept : _Extents_base(extents_type{}) {
constexpr mapping() noexcept : _Exts(extents_type{}) {
if constexpr (extents_type::rank() != 0) {
this->_Array.back() = 1;
_Strides.back() = 1;
for (rank_type _Idx = extents_type::_Rank - 1; _Idx-- > 0;) {
#if _CONTAINER_DEBUG_LEVEL > 0
const bool _Overflow =
_Mul_overflow(this->_Array[_Idx + 1], this->_Exts.extent(_Idx + 1), this->_Array[_Idx]);
const bool _Overflow = _Mul_overflow(_Strides[_Idx + 1], _Exts.extent(_Idx + 1), _Strides[_Idx]);
// NB: N4950 requires value of 'layout_right::mapping<extents_type>().required_span_size()' to be
// representable as value of type 'index_type', but this is not enough. We need to require every single
// stride to be representable as value of type 'index_type', so we can get desired effects.
_STL_VERIFY(!_Overflow,
"Value of layout_right::mapping<extents_type>().required_span_size() must be "
"representable as a value of type index_type (N4950 [mdspan.layout.stride.cons]/1).");
#else // ^^^ _CONTAINER_DEBUG_LEVEL > 0 / _CONTAINER_DEBUG_LEVEL == 0 vvv
this->_Array[_Idx] = static_cast<index_type>(this->_Array[_Idx + 1] * this->_Exts.extent(_Idx + 1));
_Strides[_Idx] = static_cast<index_type>(_Strides[_Idx + 1] * _Exts.extent(_Idx + 1));
#endif // _CONTAINER_DEBUG_LEVEL > 0
}
}
Expand All @@ -825,17 +818,17 @@ public:
&& is_nothrow_constructible_v<index_type, const _OtherIndexType&>
constexpr mapping(const extents_type& _Exts_, span<_OtherIndexType, extents_type::rank()> _Strides_,
index_sequence<_Indices...>) noexcept
: _Extents_base(_Exts_), _Strides_base{static_cast<index_type>(_STD as_const(_Strides_[_Indices]))...} {
: _Exts(_Exts_), _Strides{static_cast<index_type>(_STD as_const(_Strides_[_Indices]))...} {
#if _CONTAINER_DEBUG_LEVEL > 0
if constexpr (extents_type::rank() != 0) {
bool _Found_zero = false;
bool _Overflow = false;
index_type _Req_span_size = 0;
for (rank_type _Idx = 0; _Idx < extents_type::_Rank; ++_Idx) {
const index_type _Stride = this->_Array[_Idx];
const index_type _Stride = _Strides[_Idx];
_STL_VERIFY(_Stride > 0, "Value of s[i] must be greater than 0 for all i in the range [0, rank_) "
"(N4950 [mdspan.layout.stride.cons]/4.1).");
const index_type _Ext = this->_Exts.extent(_Idx);
const index_type _Ext = _Exts.extent(_Idx);
if (_Ext == 0) {
_Found_zero = true;
}
Expand Down Expand Up @@ -888,7 +881,7 @@ public:
&& (_Is_mapping_of<layout_left, _StridedLayoutMapping> || _Is_mapping_of<layout_right, _StridedLayoutMapping>
|| _Is_mapping_of<layout_stride, _StridedLayoutMapping>) ))
mapping(const _StridedLayoutMapping& _Other) noexcept
: _Extents_base(_Other.extents()) {
: _Exts(_Other.extents()) {
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(_STD in_range<index_type>(_Other.required_span_size()),
"Value of other.required_span_size() must be representable as a value of type index_type (N4950 "
Expand All @@ -902,18 +895,18 @@ public:
_STL_VERIFY(_Stride > 0, "Value of other.stride(r) must be greater than 0 for every rank index r of "
"extents() (N4950 [mdspan.layout.stride.cons]/7.2).");
#endif // _CONTAINER_DEBUG_LEVEL > 0
this->_Array[_Idx] = static_cast<index_type>(_Stride);
_Strides[_Idx] = static_cast<index_type>(_Stride);
}
}

constexpr mapping& operator=(const mapping&) noexcept = default;

_NODISCARD constexpr const extents_type& extents() const noexcept {
return this->_Exts;
return _Exts;
}

_NODISCARD constexpr array<index_type, extents_type::rank()> strides() const noexcept {
return this->_Array;
return _Strides;
}

_NODISCARD constexpr index_type required_span_size() const noexcept {
Expand All @@ -922,12 +915,12 @@ public:
} else {
index_type _Result = 1;
for (rank_type _Idx = 0; _Idx < extents_type::_Rank; ++_Idx) {
const index_type _Ext = this->_Exts.extent(_Idx);
const index_type _Ext = _Exts.extent(_Idx);
if (_Ext == 0) {
return 0;
}

_Result += (_Ext - 1) * this->_Array[_Idx];
_Result += (_Ext - 1) * _Strides[_Idx];
}

return _Result;
Expand Down Expand Up @@ -961,8 +954,7 @@ public:
if constexpr (extents_type::rank() == 0) {
return true;
} else {
return required_span_size()
== _Fwd_prod_of_extents<extents_type>::_Calculate(this->_Exts, extents_type::_Rank);
return required_span_size() == _Fwd_prod_of_extents<extents_type>::_Calculate(_Exts, extents_type::_Rank);
}
}

Expand All @@ -971,7 +963,7 @@ public:
}

_NODISCARD constexpr index_type stride(const rank_type _Idx) const noexcept {
return this->_Array[_Idx];
return _Strides[_Idx];
}

template <class _OtherMapping>
Expand All @@ -994,6 +986,9 @@ public:
}

private:
extents_type _Exts{};
array<index_type, extents_type::rank()> _Strides{};

template <class _OtherMapping>
_NODISCARD static constexpr _OtherMapping::index_type _Offset(_OtherMapping& _Mapping) noexcept {
if constexpr (extents_type::rank() == 0) {
Expand All @@ -1015,12 +1010,12 @@ private:
[[maybe_unused]] index_sequence<_Seq...> _Index_seq, _IndexTypes... _Indices) const noexcept {
_STL_INTERNAL_STATIC_ASSERT((same_as<_IndexTypes, index_type> && ...));
#if _CONTAINER_DEBUG_LEVEL > 0
_STL_VERIFY(this->_Exts._Contains_multidimensional_index(_Index_seq, _Indices...),
_STL_VERIFY(_Exts._Contains_multidimensional_index(_Index_seq, _Indices...),
"Value of extents_type::index-cast(i) must be a multidimensional index in extents_ (N4950 "
"[mdspan.layout.stride.obs]/3).");
#endif // _CONTAINER_DEBUG_LEVEL > 0

return static_cast<index_type>(((_Indices * this->_Array[_Seq]) + ... + 0));
return static_cast<index_type>(((_Indices * _Strides[_Seq]) + ... + 0));
}
};

Expand Down
6 changes: 0 additions & 6 deletions tests/std/tests/P0009R18_mdspan_layout_stride/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,12 +821,6 @@ constexpr void check_correctness() {
}
}

// When 'M::extents_type::rank()' is equal to 0 then 'is_empty_v<M>' should be true (MSVC STL specific behavior)
static_assert(!is_empty_v<layout_stride::mapping<dextents<long long, 2>>>);
static_assert(!is_empty_v<layout_stride::mapping<extents<long long, 3, dynamic_extent>>>);
static_assert(!is_empty_v<layout_stride::mapping<extents<long long, 3, 3>>>);
static_assert(is_empty_v<layout_stride::mapping<extents<long long>>>);

constexpr bool test() {
// Check signed integers
check_members(extents<signed char, 5>{5}, array{1});
Expand Down

0 comments on commit 73e7ba4

Please sign in to comment.