What is the past-the-end iterator in STL C++?

后端 未结 5 1836
情书的邮戳
情书的邮戳 2020-11-29 01:56

Any one could explain me what is the meaning of past-the-end. Why we call end() function past-the-end?

5条回答
  •  半阙折子戏
    2020-11-29 02:40

    Literally, because it points one past the end of the array.

    It is used because that element is empty, and can be iterated to, but not dereferenced.

    int arry[] = {1, 2, 3, 4, /* end */ };
                             ^^^^^^^
                        std::end(arry) would point here.
    

提交回复
热议问题