Re: boost alternative to realloc
* Leigh Johnston:
"Alf P. Steinbach" <alfps@start.no> wrote in message
news:hqd1em$u67$1@news.eternal-september.org...
There's no UB for writing to and subsequently reading those parts when
the element type is POD. It's just a raw array. And it's guaranteed
there.
You are not considering the fact that UB can be hierarchical, i.e.
something which is UB at one level of abstraction is not UB when you
simply consider its constituent parts at a lower level.
Sorry, I can't see the relevance. But anyway, what you thought was UB is not. I
don't think it's very relevant to the OP's problem, but it is relevant in some
other context, e.g. it's pretty handy when you call an API function where you
need a raw buffer, and this is down at a call level where efficiency matters.
If the standard
does not make it clear that v[v.size()] is UB then I would consider that
a defect (omission).
This is a different UB, perhaps this is what you meant by abstration level.
We discussed this particular UB & its specification earlier, and I tried to hint
a little, since it's Work to find the details.
But after reviewing that discussion a good place to start in the C++98 standard
might be ?24.1/6 and then ?24.1.5.
There is no section in the standard (current draft)
for std::vector's element access functions whilst there is for
std::basic_string's - this looks like an omission to me.
In the C++98 standard you find the element access functions specified in
$23.1.1/12 and $23.1.1/13.
But I share your sentiment that that spec should have been explicitly referenced
from each relevant place, e.g. from the std::vector specification, especially
considering that it's a forward reference...
It is, unfortunately, by historical accident (in the evolution TCPL -> TCPPPL ->
std), a spaghetti standard. On the bright side, that complexity ("complexity" is
a euphemism for "spaghetti") allows room for much entertaining discussion. We've
not yet reached the level where all C++ programmers subscribe to the religion of
the Flying Spaghetti Monster, but we do refer to the Holy Standard. ;-)
Cheers & hth.,
- Alf