Iterators Must Go

Rainer Deyke rainerd at
Sat May 9 16:32:35 PDT 2009

Although I like ranges, it looks to me like there are a couple of
operations that would difficult to implement without iterators or some
other way to specify a specific position in a range.

Finding and erasing an element:
  list.erase(find(list.begin(), list.end(), e));

Splitting a container on a position:
  iter = find(list.begin(), list.end(), e);
  do_something_with(list.begin(), iter);
  do_something_else_with(iter, list.end());

Inserting into a container at a position:
  iter = find(list.begin(), list.end(), e);
  list.insert(iter, array.begin(), array.end());

Constructing a range from two independent position:
  iter1 = find(list.begin(), list.end(), e1);
  iter2 = rfind(list.begin(), list.end(), e2);
  do_something_with(iter1, iter2);

Rainer Deyke - rainerd at

More information about the Digitalmars-d mailing list