Is begin() == end() for any empty() vector?

后端 未结 4 1033
花落未央
花落未央 2020-12-15 02:19

I have long assumed that for any empty std::vector V, V.begin() == V.end(). Yet I see nothing in the C++ specification that states this to

4条回答
  •  醉梦人生
    2020-12-15 03:00

    23.2.1 General container requirements, specifically Table 96 Container Requirements has

    a.empty() convertible to bool, operational semantics a.begin() == a.end()

    Then

    6 begin() returns an iterator referring to the first element in the container. end() returns an iterator which is the past-the-end value for the container. If the container is empty, then begin() == end();

    (emphasis mine)

提交回复
热议问题