开发者

What is the address of back() in an empty container?

开发者 https://www.devze.com 2022-12-18 23:45 出处:网络
I mistakenly took the address of the reference returned by the back() operator in an empty container and was surprised to see that the address wasn\'t zero.

I mistakenly took the address of the reference returned by the back() operator in an empty container and was surprised to see that the address wasn't zero.

If a container e.g. std::deque is 开发者_运维技巧empty, what does back() return?


it returns the last element.

on this page: http://www.sgi.com/tech/stl/BackInsertionSequence.html

precondition: !a.empty()

Equivalent to *(--a.end()).

since the precondition is the deque is not empty, then it means it's undefined behavior.


Calling front or back on an empty standard container results in undefined behavior.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号