October 14th, 2010, 10:07 pm
QuoteOriginally posted by: renormHow about this? Is it legal?would it work? probablyThe vector wouldn't change its memory for a shrink in size so you wouldn't have memory problems. v[11] is equivalent to *(v.begin()+11)24.1.5 "The library never assumes that past-the-end values are dereferenceable."However, you are doing a[11] not v[11] so the issue is solely whether the memory would shrink. A quick look at the standard was not overly clear. There is an implication that as long as the capacity does not increase the memory will not be reallocated so you should be ok.
Last edited by
mj on October 14th, 2010, 10:00 pm, edited 1 time in total.