-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add element access via at()
to std::mdspan
#302
base: stable
Are you sure you want to change the base?
Conversation
at()
to std::mdspan
9e59d6e
to
7b3a6e0
Compare
Given that SizeTypes can be signed, it should also check for indices[r] < 0. |
Thanks for this comment! Is this true for |
In |
Ah right, thanks for pointing this out! Edit: updated the pull request |
7b3a6e0
to
0accddc
Compare
Signed-off-by: Stephan Lachnit <stephanlachnit@debian.org>
Signed-off-by: Stephan Lachnit <stephanlachnit@debian.org>
0accddc
to
4cff9ce
Compare
// Check for negative indices | ||
if constexpr(std::is_signed_v<SizeType>) { | ||
if(index < 0) { | ||
return true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SizeType
doesn't need to be integral here or even less-than comparable with int
. mdspan behaves as if all operations on indices happen after conversion to index_type
. Thus, should we consider instead converting to index_type
first, as we do below?
// Check for negative indices | |
if constexpr(std::is_signed_v<SizeType>) { | |
if(index < 0) { | |
return true; | |
} | |
} | |
// Check for negative indices | |
if constexpr (std::is_signed_v<index_type>) { | |
if (static_cast<index_type>(index) < 0) { | |
return true; | |
} | |
} |
Closes #300
Possible implementation for ::at element access to mdspan with boundary checks. The boundary check is implemented with a for loop, as I did not see any other way to achieve this. The error message is inspired by the
std::span::at
error message from libstdc++ (gcc-mirror/gcc@1fa85dc).Note that this does not implement ::at element access to mdarray.