4 ms·
> C++ is about don't pay for what you don't use, and if you don't need the bounds check you shouldn't have to pay for it. There's a good compromise here though
by oconnor663 4y ago
> C++ is about don't pay for what you don't use, and if you don't need the bounds check you shouldn't have to pay for it.
There's a good compromise here though: do the bounds checks by default in operator[], and provide a separate get_i_know_what_im_doing() method that omits the bounds checks, which the programmer can call as an optimization. The fast/unsafe thing needs to be available, but it doesn't need to be the most convenient syntax.
I'm sure there are backwards compatibility problems with making a behavior change like that now, but I'm guessing e.g. CppFront is making that choice from the start? (Edit: sounds like it, if this is up to date: https://github.com/hsutter/cppfront/issues/110#issuecomment-1355947643 https://github.com/hsutter/cppfront/issues/110#issuecomment-... )