
6 Dec
2024
6 Dec
'24
10:15 p.m.
Yes, that's the naive way to implement it. Like I said, depending how dedicated you are, in modern C++ you can pretty much just fold something like that in an elegant way. Also, you need to understand that "just using a pointer" doesn't necessarily mean no checks either in many cases. I think the main issue here is that with span we can eliminate all the arithmetic around subscript access, which makes code more readable, and harder to get wrong, while delivering the same result, and with tools that allow us to provide the compiler with more information about what we are doing. So the overall result is something more robust than "just a pointer", and the safety becomes just a natural conclusion of this. Claudio.