Empty std::vector begin != end

Empty std::vector begin != end

本文关键字:end vector std Empty begin      更新时间:2023-10-16

我想知道是否有人经历过空向量,但开始和结束迭代不一样?

感谢

这应该是不可能的。该标准在【集装箱要求概述】/6 中进行了说明

begin()返回一个迭代器,该迭代器引用容器中的第一个元素。end()返回一个迭代器是容器的过期结束值。如果容器是空的,则begin() == end();

因此,如果contianer.empty() == true,则container.begin()必须等于container.end()