How is end() implemented in STL containers?

后端 未结 6 2379
小蘑菇
小蘑菇 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:50

    STL ensures this behavior by always storing stuff like this:

    vector

    In the end (pun), it doesn't matter what end() is, as long as it's always end() (and, obviously, can't be confused with any other node).

提交回复
热议问题