You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I saw you removed boundary checking in operator[], but later you undid that change. What is your rationale of either adding or removing it?
My view is, that the general C++ philosophy of zero-cost abstractions and "don't pay for what you don't use" is violated by performing bounds checking when indexing. Indexing should be unchecked, if the user desires boundary checking behaviour, she can always opt-in by using the at() member function.
This is the general consensus in the STL, e.g. in std::vector and std::array.
What do you think?
Thanks,
Márton
The text was updated successfully, but these errors were encountered:
marton78
changed the title
Boundary check of operator[]
Boundary checking in operator[]
Jul 11, 2016
Bounds.1: Don't use pointer arithmetic. Use span instead.
Reason
Pointers should only refer to single objects, and pointer arithmetic is fragile and easy to get wrong. span is a bounds-checked, safe type for accessing arrays of data.
Hi,
I saw you removed boundary checking in
operator[]
, but later you undid that change. What is your rationale of either adding or removing it?My view is, that the general C++ philosophy of zero-cost abstractions and "don't pay for what you don't use" is violated by performing bounds checking when indexing. Indexing should be unchecked, if the user desires boundary checking behaviour, she can always opt-in by using the
at()
member function.This is the general consensus in the STL, e.g. in
std::vector
andstd::array
.What do you think?
Thanks,
Márton
The text was updated successfully, but these errors were encountered: