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

前端 未结 6 2403
感动是毒
感动是毒 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 02:58

    at() returns the element with index i and throws range error exception if index i is out of range . so i would suggest using at() rather than [] since it yields undefined behavior if out of range. if you want safety in your proggy use at() :).

提交回复
热议问题