Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-09-24 20:44:13


Jens Theisen <jth02_at_[hidden]> writes:

> Hello,
>
> I'm wondering what the reference member in the iterator_traits of an
> iterator is required to be. I couldn't find any requirement at all in
> the C++98 standard,

Bingo.

> and more surprisingly, I can't see any requirement
> in the new iterator proposal either.
>
> In particular, operator* does not seem to be required to return the
> iterator_traits< Iterator >::reference for lvalue iterators.

Interesting point. IIRC we were trying to stay compatible with the
existing standard iterators; one of the iterators (istream_iterator?)
has a very strange reference type.

OTOH, for lvalue iterators, the reference member
is redundant: the result of operator* is reqiured to be value_type&

> At one point, however, the proposal suggests that this was the
> intention:
>
> "...would have a return type of reference; the same as operator*."
>
> where reference has a font style indicating that it's the
> iterator_traits's notion of reference.
>
> I'm looking at the proposal version currently published along in the
> documentation of the boost iterator library.
>
> So my questions:
>
> - Am I right in my suspicion that in the STL, the reference
> iterator_trait is entirely useless if taken strictly?

Yes.

> - Should the proposal not better require the reference to match with
> operator*'s return type for lvalue iterators? If not, what's its
> use?

Maybe, but that particular proposal is sorta dead. Some people have
been working on a new one to address these issues, but I don't know
where it's going.

> - Is this off-topic here? :)

It's marginally on-topic, I s'pose.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net