Skip to content

Commit

Permalink
layout_right: cleanup names
Browse files Browse the repository at this point in the history
Partially addresses microsoft#3564 (comment)
  • Loading branch information
JMazurkiewicz committed Mar 25, 2023
1 parent 3dc3965 commit ada70c4
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions stl/inc/mdspan
Original file line number Diff line number Diff line change
Expand Up @@ -413,51 +413,50 @@ template <class _Extents>
class layout_right::mapping {
public:
using extents_type = _Extents;
using index_type = typename _Extents::index_type;
using size_type = typename _Extents::size_type;
using rank_type = typename _Extents::rank_type;
using index_type = typename extents_type::index_type;
using size_type = typename extents_type::size_type;
using rank_type = typename extents_type::rank_type;
using layout_type = layout_right;

static_assert(_Is_extents<_Extents>,
static_assert(_Is_extents<extents_type>,
"Extents must be a specialization of std::extents (N4928 [mdspan.layout.right.overview]/2).");
static_assert(_Extents::_Is_index_space_size_representable(),
static_assert(extents_type::_Is_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.");

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

constexpr mapping(const _Extents& _Ext) noexcept : _Myext(_Ext) {}
constexpr mapping(const extents_type& _Exts_) noexcept : _Exts(_Exts_) {}

template <class _OtherExtents>
requires is_constructible_v<extents_type, _OtherExtents>
constexpr explicit(!is_convertible_v<_OtherExtents, _Extents>)
constexpr explicit(!is_convertible_v<_OtherExtents, extents_type>)
mapping(const mapping<_OtherExtents>& _Other) noexcept
: _Myext{_Other.extents()} {}
: _Exts(_Other.extents()) {}

template <class _OtherExtents>
requires (extents_type::rank() <= 1) && is_constructible_v<extents_type, _OtherExtents>
constexpr explicit(!is_convertible_v<_OtherExtents, _Extents>)
constexpr explicit(!is_convertible_v<_OtherExtents, extents_type>)
mapping(const layout_left::mapping<_OtherExtents>& _Other) noexcept
: _Myext{_Other.extents()} {}
: _Exts(_Other.extents()) {}

template <class _OtherExtents>
requires is_constructible_v<extents_type, _OtherExtents>
constexpr explicit(_Extents::rank() > 0) mapping(const layout_stride::template mapping<_OtherExtents>& _Other)
: _Myext{_Other.extents()} {}
constexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::template mapping<_OtherExtents>& _Other)
: _Exts(_Other.extents()) {}

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

_NODISCARD constexpr const extents_type& extents() const noexcept {
return _Myext;
return _Exts;
}

_NODISCARD constexpr index_type required_span_size() const noexcept {
index_type _Result = 1;
for (rank_type _Dim = 0; _Dim < _Extents::rank(); ++_Dim) {
_Result *= _Myext.extent(_Dim);
for (rank_type _Dim = 0; _Dim < extents_type::rank(); ++_Dim) {
_Result *= _Exts.extent(_Dim);
}

return _Result;
}

Expand All @@ -466,7 +465,7 @@ public:
&& (is_nothrow_constructible_v<index_type, _Indices> && ...)
_NODISCARD constexpr index_type operator()(_Indices... _Idx) const noexcept {
return _Index_impl<conditional_t<true, index_type, _Indices>...>(
static_cast<index_type>(_Idx)..., make_index_sequence<_Extents::rank()>{});
static_cast<index_type>(_Idx)..., make_index_sequence<extents_type::rank()>{});
}

_NODISCARD static constexpr bool is_always_unique() noexcept {
Expand Down Expand Up @@ -497,8 +496,8 @@ public:
requires (extents_type::rank() > 0)
{
index_type _Result = 1;
for (rank_type _Dim = _Rank + 1; _Dim < _Extents::rank(); ++_Dim) {
_Result *= _Myext.extent(_Dim);
for (rank_type _Dim = _Rank + 1; _Dim < extents_type::rank(); ++_Dim) {
_Result *= _Exts.extent(_Dim);
}

return _Result;
Expand All @@ -511,12 +510,12 @@ public:
}

private:
_Extents _Myext{};
extents_type _Exts{};

template <class... _IndexType, size_t... _Seq>
constexpr index_type _Index_impl(_IndexType... _Idx, index_sequence<_Seq...>) const noexcept {
index_type _Result = 0;
((void) (_Result = _Idx + _Myext.extent(_Seq) * _Result), ...);
((void) (_Result = _Idx + _Exts.extent(_Seq) * _Result), ...);
return _Result;
}
};
Expand Down

0 comments on commit ada70c4

Please sign in to comment.