I noticed today that std::vector::at()
is significantly slower than accessing values with square brackets []
. According to the doc .at()
i
at() throws an out_of_range exception, which [] doesn't do.
So while [] might make your application crash immediately if you try to access something out of range, at() will enable to you to handle the error at runtime.
If this is necessary for you (often times it won't be because accessing something out of range automatically means that the semantics of your code don't work as they're supposed to) you should use at().