mdspan
mdspan copied to clipboard
mdspan: Add optional bounds checking
Both default_accessor and layout_{left, right, stride}::mapping::operator() have in-bounds access as a precondition. This permits implementations to add bounds checking, using whatever mechanism they like (as precondition violations are undefined behavior).
- [ ] Add a configure-time option to turn on bounds checking.
- [ ] Use macros to protect bounds checking and error reporting code, including header file includes like
<iostream>. (The test and branch have a nonzero run-time cost. Also, code for printing error messages can costs compilation time and possibly also performance (e.g., extra registers in device code).) - [ ] Add a test that only runs if bounds checking is turned on. Consider adding a build for that case.
I think that we may additionally add the .at() method , like in std::vector, and, possibly, some kind of explicit bound checks method like item_in_range(Index... Idx)
I also may cook a proposal with this feature 😅