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

前端 未结 6 2378
感动是毒
感动是毒 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:11

    Assuming your not using exceptions as some sort of signal-system, the difference is that vector::at() will ALWAYS throw an exception when you try to access an index out of bounds. vector::operator[] might either return an undefined value OR throw an access violation exception (or crash).

提交回复
热议问题