From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-01-11 08:53:32
----- Original Message -----
From: "Toon Knapen" <toon.knapen_at_[hidden]>
> Should'nt the dereference() in the policies return a const_reference
> instead of a reference ?
How would you build a mutable iterator with that?
> I'm using a projection_iterator to navigate over a sequence and my
> UnaryFunction returns a const reference. This results in a compiler
> error (gcc-3.0.3).
It sounds like your function returns T const& but you made the iterator's
reference type plain T&. That's a no-no.
Or, perhaps you are returning a U& but you made your function's result_type
U& instead of U. It looks like the projection_iterator assumes you followed
the model of the standard's reference-returning function objects (e.g.
> Particular in the case of the projection_iterator, the 'function' is a
> one way function (able to convert the real content to the iterator's
> value_type and not vice-versa, thus the iterator can never be writeable)
That might be a job for transform_iterator. Where does the reference come
> and thus only a 'dereference() const' is possible returning a
> const_reference IMHO ?
There is no const_reference typedef.
However, it would make sense for projection_iterator_adaptor to be able to
cope with function objects whose result_type is a reference, at least when
partial specialization is available. Would you care to contribute a simple
patch? Most of the work goes into expanding the test suite; aside from that
you just need remove_const< remove_reference< result_type >::type >::type in
the generator to get the value_type.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk