Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-12-28 11:21:03

----- Original Message -----
From: "Bernard HUGUENEY" <bernard.hugueney_at_[hidden]>

> Hi,
> I'm greatly interested by iterator_adaptor, and currently (ab)using it a
> It really made me rewrite as much of my own stuff as time permitted to
make my iterators "right".
> I'm currently experiencing troubles when composing some iterators:
> when I retrun a dereference() value, it is by reference, but if the
underlying iterator (as one from
> counting_iterator_policies) returns by value, the compiler complains that
I take the reference to the
> temporary underlying return value :-(

Hi Bernard,

Sorry it took me so long to respond.

If you are willing to have your composed iterator be only a ForwardIterator
or OutputIterator, you can return a non-reference type from dereference()
(All other iterator categories require that the type of a dereferenced
iterator be a reference type). The only other way to build an iterator whose
dereference() returns a reference atop an iterator which doesn't return a
reference type when dereferenced is to store the value somewhere (e.g. in
the iterator itself) so you can return a reference to it.

> Would it be possible to fix integer_range?

Hmm, I guess integer_range /is/ broken because its iterator_category is
random_access_iterator_tag but it returns a non-reference type from
dereference(). It looks to me like this would be trivial to fix.

> Or what would be the correct workaround ? It might be that
counting_iterator_policies is correct :-(

No, I think you've found a problem. Jeremy, is there a way to use concept
checks to make sure that people don't give iterator tags >= ForwardIterator
to things that return non-reference types from dereference?

> I guess that means I should specialize my iterator wrappers to hold a copy
> of the dereferenced iterator is it's iterator_traits<>::reference is not
one, but I'd rather not...

Sorry, I can't parse that sentence.

> A problem, I believe, lie in the fact that the refreturned is not const,
and dereference() takes a const iterator. I did not
> find any satisfying solution (my code uses const_cast<>), but I'no guru
myself :-)
> Anyway, thank you for the great work, I'm always more than happy to
rewrite code when it involves using some
> "treasures from the vault" :-)


Boost list run by bdawes at, gregod at, cpdaniel at, john at