In message <e06439$m7a$00$1@news.t-online.com>, Rolf Magnus
<ramagnus@t-online.de> writes[color=blue]
>Mark P wrote:
>[color=green]
>>
al.cpwn@gmail.com wrote:[color=darkred]
>>> Is there a reason why erase for vector returns an iterator but erase
>>> for set doesn't? Is this something we should keep in mind while
>>> designing our own containers (like binary tree for example)?
>>>[/color]
>>
>> My guess is that this is because in the vector case, the call to erase
>> will invalidate all iterators at or beyond the location of the erasure.
>> Thus it's useful to return a new iterator to the location after the
>> erasure.
>>
>> For a set, only iterators pointing to the location of the erasure are
>> invalidated, so this is easier to deal with manually. For example,
>> mySet.erase(myIter++); will result in myIter pointing to the location
>> after the erasure.[/color]
>
>However, they could still have let set's erase return an iterator too, for
>the sake of constistency.[/color]
But incrementing set::iterator may be costly, since it involves some
O(log(N)) tree navigation. Why pay for something you don't need?
--
Richard Herring