Boost logo

Boost :

Subject: Re: [boost] type of iterator_facade::value_type
From: David Abrahams (dave_at_[hidden])
Date: 2010-01-28 22:45:47


At Wed, 23 Dec 2009 09:02:11 -0800,
Steven Watanabe wrote:
>
> AMDG
>
> Neal Becker wrote:
> > According to iterator_facade doc:
> >
> > typedef remove_const<Value>::type value_type;
> >
> > Why remove_const?
>
> This is what the standard does.

And with good reason: it would be wicked inconvenient if you tried to
declare a variable of the value type and then found you couldn't
modify it.

> > This makes it hard to detect if the resulting iterator
> > points to a const value.
>
> value_type is intended to give a type that can be used for temporaries, etc.
> It was not designed as a general purpose type deduction mechanism.

Exactly.

> For this purpose, reference is better because reference gives the
> exact type from dereferencing the iterator.
>
> > In order to further adapt such an iterator, I needed to use the
> > reference type instead of the value type to detect constness:
> >
> > typename boost::is_const<
> > typename boost::remove_reference<
> > typename std::iterator_traits<BaseIterator>::reference
> > >::type
> > >::type,
>
> Yes. Although this is insufficient because it doesn't handle
> proxies or rvalues.

Right. Why are you trying to detect iterator constness? It's hard
for me to imagine a good use for that.

-- 
Dave Abrahams           Meet me at BoostCon: http://www.boostcon.com
BoostPro Computing
http://www.boostpro.com

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