How is end() implemented in STL containers?

后端 未结 6 2380
小蘑菇
小蘑菇 2021-02-19 12:32

So when we need to traverse a container from start to end we write something like

for (i = v->begin(); i != v->end(); i++)

assuming i

6条回答
  •  死守一世寂寞
    2021-02-19 12:40

    You're asking about all STL containers... not a word of mention of vector specifically where end() might be implemented as you obviously intuitively expect. What's one past the end in a std::map<>? The "end is one past the last used node" thing is just a logical concept, expressing that you can safely increment from that last-used node, differentiate/equate it from/to the abstract concept of "end", and do some node arithmetic where end is considered to be one further along than the last-used node. Don't take it too literally.

提交回复
热议问题