mdspan
mdspan copied to clipboard
Add element access via `at()` to `std::mdspan`
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++ (https://github.com/gcc-mirror/gcc/commit/1fa85dcf656e2f2c7e483c9ed3c2680bf7db6858).
Note that this does not implement ::at element access to mdarray.
Given that SizeTypes can be signed, it should also check for indices[r] < 0.
Given that SizeTypes can be signed, it should also check for indices[r] < 0.
Thanks for this comment! Is this true for std::span as well? At least in libstdc++, they do not check this:
https://github.com/gcc-mirror/gcc/blob/fd7dabc116b9abc40ee6aa25bcc5d240b8cc516a/libstdc%2B%2B-v3/include/std/span#L290-L300
In span, I believe it's always just std::size_t, but mdspan has the size type as a template parameter for the extent and can be signed.
In
span, I believe it's always juststd::size_t, butmdspanhas the size type as a template parameter for the extent and can be signed.
Ah right, thanks for pointing this out!
Edit: updated the pull request
if constexpr doesn't exist pre C++17, should I add a macro here? Or just go with if and assume the compiler optimizes for this anyway?
I don't quite get the build failure on MSVC, would need some help there...
I don't quite get the build failure on MSVC, would need some help there...
What if you used the requires clause from operator()? I think that operator[] is not used in the MSVC build so we may not have updated it:
MDSPAN_TEMPLATE_REQUIRES(
class... SizeTypes,
/* requires */ (
extents_type::rank() == sizeof...(SizeTypes) &&
(detail::are_valid_indices<index_type, SizeTypes...>())
)
)
@stephanlachnit My apologies, we recently fixed a bunch of naming changes. Would you mind rebasing? If you don't have the time I can take this over just let me know. It would be very nice to have this merged in
@stephanlachnit My apologies, we recently fixed a bunch of naming changes. Would you mind rebasing? If you don't have the time I can take this over just let me know. It would be very nice to have this merged in
If you want to take over feel free to do so
Closing as it is superseded by https://github.com/kokkos/mdspan/pull/400