Consider:
#include
int main()
{
std::vector v;
v.reserve (100);
v[1] = 42;
}
I am aware that the above code i
It's an outgrowth of how operator[]
is defined. In §23.2.3 [sequence.rqmts] Table 101, the Operational Semantics of operator[]
is defined as *(a.begin() + n)
. So it's defined in terms of iterators. And incrementing begin
past end
and dereferencing it is undefined behavior according to §24.2.1/5 [iterator.requirements.general].