Boost logo

Boost :

From: Hayati Ayguen (Ayguen_at_[hidden])
Date: 2001-07-17 02:17:33


i don't think your approch is a better one. you're replacing one problem
with another one:


has just the problem of foreholding the old value. this needs space and
a kind of copy operator has to be called internally.

calling erase and increment seperately would solve the problem:


this doesn't look fine, but it works: neither space nor time is


  it = c.erase(it);

solves the space problem, but not the copy/define operation! for complex
iterators where the iterator class has many member variables, one should
avoid such a design, where an implicit or explicit copy has to be

if you find (2) a problem, you may define erase() in the iterator class
internally calling the princrement operator but returning "void":

  void it.erase();

  void Iterator::erase()

but this would break the semantics of erase() from namespace std.

Hayati Ayguen

> Hi All,
> IMO, the current state of affairs for erasing elements from a
> container is somewhat unsatisfactory for average programmers.
> For some of the containers (std::set, std::map), erase is a "void"
> method - in which case the correct action is to keep a copy of the
> increment iterator beforehand, like this:
> c.erase(it++)
> But for other containers (e.g. std::vector), the correct action is to
> take the return value of erase:
> it = c.erase(it);
> ....
> Paul Hollingsworth

Boost list run by bdawes at, gregod at, cpdaniel at, john at