[C++-sig] Re: Support for Indexing and Iteration Safety

David Abrahams dave at boost-consulting.com
Thu May 29 23:51:33 CEST 2003


"Mike Rovner" <mike at bindkey.com> writes:

> "David Abrahams" <dave at boost-consulting.com> wrote in message
> news:u4r3dzibn.fsf at boost-consulting.com...
>> Mike, please take this discussion to the C++-sig...
> It is there. I did courtesy CC: when posted to -sig because original mail
> felt into my e-mail inbox. ;)
>
>> >   static void del(T& x, int n) {
>> >     if( n<0 ) n+=x.size();
>> >     if( n<x.size() && n>=0 ) x.erase(&x[n]);
>> >     else IndexError(); }             ^^^^^
>> > };                                   ^^^^^
>>                                    Doesn't work (not an iterator).
> Sorry. I'm spoiled by MSVC. Hope x.erase( Container<T>::iterator(&x[n]) )
> will do?
> (with proper Container type)

No, it won't.  Not even with VC7. Something wrong with
x.erase(x.begin() + n)?

>> I have something a little less simplistic in mind.  Why shouldn't
>> everyone benefit? ;-)
>
> It will be very nice thing to have.
>
>> > My 0.02. Hope I made my point clear.
>>
>> Not really.  The clearest message I can discern is "there's really not
>> much of a problem". Is that really what you're saying?
>
> Not really. In my case I made it so with very simplistic approach
> AND reducing my usage pattern.  I recall my surprise it isn't in
> place and sure agree with your answer "loud NO" to any unpredictable
> behavior.  So I understand why it's better not to have then have
> unreliable.  I tried to argue in support of having something shall
> be reliable out of the box.  

I thought you were arguing for "return by value" as a default.  If we
accept the argument for "return by value" we are left unable to modify
array elements:

     foo[x].bar = 1

If we accept simplistic return-by-reference we get a lack of safety.

> For that goal it may be not the fastest and not the simplest.

Agreed.





More information about the Cplusplus-sig mailing list