Boost logo

Boost :

From: Glen Knowles (gknowles_at_[hidden])
Date: 2002-08-01 21:44:33


> > I believe begin() should return a const iterator, you then assign it to
a
> > non-const iterator ("it" above) and then inc/dec the copy.
>
> I doubt users would find that attractive. You would have to cast away
> const.

How so? We're making a copy, not modifying the original. As in (tested):

const vector<int>::iterator iter(vector<int>& vec) { return vec.begin(); }

int main() {
  vector<int> vec;
  vector<int>::iterator iv = iter(vec);
  ++iv;
}

> Furthermore, the Standard Library container requirements, table 65,
require
> that the return type of begin() be "iterator", not "const iterator".

That may be a good enough argument, although I don't see any advantages to
"iterator" over "const iterator".

Glen



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk