|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-08-02 12:00:02
From: "Beman Dawes" <bdawes_at_[hidden]>
> At 08:26 AM 8/2/2002, Peter Dimov wrote:
>
> >From: "Beman Dawes" <bdawes_at_[hidden]>
>
> >> ... path::begin() can't return a const iterator; iteration
> >>(operator++, operator--) wouldn't work!
> >
> >++p2.begin() already doesn't work. An iterator is not required to be a
> >class type, and therefore, its rvalues aren't required to support ++.
All
>
> >built-in rvalues, despite being non-qualifiable, are de-facto const.
>
> You're right. I always forget that.
>
> What to do about it? See my reply to Darin.
Returning a const-qualified iterator is probably the right choice. Although
strictly speaking this doesn't conform to the standard library conventions
that document begin()/end() returning a non-const qualified iterator, I've
always thought that const returns better reflect the intent.
When the iterator is a pointer, the const qualifier will be ignored (by
conforming compilers.)
The only portability problem with returning "iterator const" is that
template<class T> void f(T & t);
f(p2.begin());
will now work when the iterator is a class type, but this is probably pretty
rare.
> PS: The Standard itself uses --a.end() twice in the optional sequence
> operations table!
ISTR an issue about it... there it is:
http://std.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#355
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk