Re: Interpretation of Effects in the C++ standard
James Kanze schrieb:
Daniel Kr?gler wrote:
[..]
Is this implementation conforming or not?
Certainly not. Consider the following:
std::vector< int > v ;
v.reserve( 200 ) ;
static int i[] = { 1, 2, 3 } ;
v.assign( i, i + 3 ) ;
std::vector< int >::iterator iter = v.begin() + 2 ;
for ( i = 4 ; i < 100 ; ++ i ) {
v.push_back( i ) ;
}
At this point, the standard requires iter to still be valid.
Your version of assign would break this.
Yikes, thanks for reminding me to this! I should have thought a little
bit longer about that.
I further wonder, why the assign function is not part of the container
or sequence requirements. Can someone enlighten me concerning
this?
A priori, because it isn't required:-). In the case of
containers in general, I'd say that this is correct. Containers
are not required to support insert, and may have a fixed size,
so you cannot assign an arbitrary sequence to them. In the case
of sequences... it is required, at least in the current draft.
Nice to hear that - I only looked in my 2nd edition (ISO 14882-2003)
and if I had read my own quotation a little bit more carefully I would
have recognized that this issue had already been mentioned by
Howard Hinnant in his report....
Greetings,
Daniel
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]