mdspan icon indicating copy to clipboard operation
mdspan copied to clipboard

mdspan: Add optional bounds checking

Open mhoemmen opened this issue 1 year ago • 1 comments

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.

mhoemmen avatar Aug 26 '22 21:08 mhoemmen

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 😅

leha-bot avatar Apr 03 '23 18:04 leha-bot