Should I use std::vector::at() in my code

前端 未结 6 2416
感动是毒
感动是毒 2021-02-19 02:17

I noticed today that std::vector::at() is significantly slower than accessing values with square brackets []. According to the doc .at() i

6条回答
  •  时光取名叫无心
    2021-02-19 03:05

    The difference between at() and the operator[] is that at() signals if the requested position is out of range by throwing an out_of_range exception.
    So with the at() you can react to the error state. Using the operator[] to access the vector out of index will result in undefined behavior.

提交回复
热议问题