Does std::list::clear invalidate std::list::end iterator?

前端 未结 3 1432
眼角桃花
眼角桃花 2021-02-20 01:01

Check this code:

#include \"stdafx.h\"
#include 

int _tmain(int argc, _TCHAR* argv[])
{
    std::list mylist;
    mylist.push_back(1);
          


        
3条回答
  •  -上瘾入骨i
    2021-02-20 01:46

    From C++11, Table 100 (Sequence container requirements):

    clear() [...] may invalidate the past-the-end iterator.

    And std::list is of course a sequence container template (23.3.5.1/2):

    A list satisfies all of the requirements of a container, of a reversible container (given in two tables in 23.2), of a sequence container, including most of the optional sequence container requirements (23.2.3), and of an allocator-aware container (Table 99). The exceptions are the operator[] and at member functions, which are not provided. Descriptions are provided here only for operations on list that are not described in one of these tables or for operations where there is additional semantic information.

提交回复
热议问题