Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<mdspan>: Implement *Mandates* clauses #3535

Merged

Conversation

JMazurkiewicz
Copy link
Contributor

@JMazurkiewicz JMazurkiewicz commented Mar 4, 2023

  • Implement all Mandates clauses from [views.multidim]:
    • std::extents now accepts all signed and unsigned integer types (as TRANSITION comments said),
    • Fix checking if all Extents are representable as IndexType,
    • Rename _Is_extents to _Is_extents_v to indicate that this is a variable, Standard suggest name is-extents without -v suffix ([mdspan.layout.stride.expo]/3),
    • Add missing checks in mdspan class,
    • Add messages for assertions in mdspan constructor,
    • LWG-3876 - checked by extents::_Is_index_space_size_representable function (this name can be much better, so I'm open for suggestions),
    • Add extra static_assertions for [mdspan.layout.left.overview]/2, [mdspan.layout.right.overview]/2, and [mdspan.layout.stride.overview]/2.
  • Drive-by - more renames:
    • e -> _Ext (non-reserved identifier),
    • OtherExtents -> _OtherExtents (ditto),
    • r -> _Rank (ditto),
    • Remove unnecessary semicolon at the end of function definition (several occurrences),
    • Remove parameter (with unreserved) name from defaulted/deleted functions.
  • Extra: _NODISCARD friend -> _NODISCARD_FRIEND
  • Tests:
    • Custom accessors missed element_type nested type,
    • Fix typo: constuctible -> constructible.

@JMazurkiewicz JMazurkiewicz requested a review from a team as a code owner March 4, 2023 00:40
@StephanTLavavej StephanTLavavej added the mdspan C++23 mdspan label Mar 4, 2023
stl/inc/mdspan Outdated Show resolved Hide resolved
Copy link
Contributor

@MattStephanson MattStephanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking up some of the work!

stl/inc/mdspan Outdated Show resolved Hide resolved
stl/inc/mdspan Show resolved Hide resolved
stl/inc/mdspan Outdated Show resolved Hide resolved
JMazurkiewicz and others added 2 commits March 4, 2023 08:01
Co-authored-by: Matt Stephanson <68978048+MattStephanson@users.noreply.github.com>

_NODISCARD static constexpr bool _Is_index_space_size_representable() {
if constexpr (rank_dynamic() == 0 && rank() > 0) {
return _STD in_range<index_type>((_Extents * ...));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to worry about integer overflow during this monster multiplication?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only references I could find to index_type being able to represent the index space size are in Preconditions to the various layout mapping constructors. If we're going to upgrade it to a static_assert, then I think we do need to check for overflow, because it can happen and the compiler is supposed to diagnose UB in constant evaluation contexts. We also don't want any false positives, since the user won't have any way to bypass this check.

stl/inc/mdspan Show resolved Hide resolved
stl/inc/mdspan Show resolved Hide resolved
stl/inc/mdspan Show resolved Hide resolved
@StephanTLavavej StephanTLavavej merged commit 0314b17 into microsoft:feature/mdspan2 Mar 4, 2023
@StephanTLavavej
Copy link
Member

Thanks! My suggestions (if you agree with them) can be addressed in followup PRs.

@JMazurkiewicz JMazurkiewicz deleted the mdspan/mandates branch March 5, 2023 12:09
JMazurkiewicz added a commit to JMazurkiewicz/STL that referenced this pull request Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mdspan C++23 mdspan
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants