All standard iterator and container types behave the same in this regard:
§23.2.1 [container.requirements.general] p6
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()
;
And table 107 in §24.2.3 [input.iterators]
demands that as a precondition for ++it
, it
shall be dereferenceable, which is not the case for past-the-end iterators (i.e., what you get from end()
), as such you're treading into the dreaded domain of undefined behaviour.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…