I noticed today that std::vector::at()
is significantly slower than accessing values with square brackets []
. According to the doc .at()
i
at
does range check, but operator[]
does not. For example, if you pass -1 to at()
, an std::out_of_range
will be thrown. But if you do the same thing to operator[]
it will crash or strange things will happen.
If you are absolutely sure that the index is OK or you want to do the check yourself, use operator[]
.