|
|
|
|
|
by constantcrying
1302 days ago
|
|
I imagine the reason bounds check are cheap is because of the branch predictor.
If you always predict the in bounds path, the check is almost free. You also do not really care about flushing the pipe on an out of bounds index, since very likely normal operations can not go on and you move over to handling/reporting the error, which likely has no need for significant throughput. Also I would just like to note that safe arrays aren't a unique rust feature. Even writing your own in C++ is not hard. |
|
These days, C++ really should be compiled with bounds-checked indexing and iterators by default. Unfortunately, this is still not a scenario that is well-supported by tooling.