Boost logo

Boost :

Subject: Re: [boost] [iterator] iterator_facade reference type problem
From: Jeffrey Hellrung (jhellrung_at_[hidden])
Date: 2010-01-14 14:22:33


Phil Endecott wrote:
> I've done some more experiments, and it seems to work with
> std::pair<const KEY, value&> if i write (*iter).second rather than
> iter->second.
>
> Looking at the iterator_facade source, operator-> calls operator* and
> passes the result to operator_arrow_result::make(). This takes its
> address and, because std::pair<const KEY,VALUE&> is not a reference, it
> tries to convert it to operator_arrow_proxy<...>. This fails because
> std::pair<const KEY,VALUE&> is not convertible to std::pair<KEY,VALUE>.
>
> I think I just want operator-> to return a pointer to my reference type,
> but the operator_arrow_result stuff is trying to do something more
> complicated. In what case is the operator_arrow_proxy useful? Is there
> some way to get what I want using iterator_facade?
<snip>
> BTW I have been testing with an oldish version of Boost, but I've looked
> at the source in svn and it doesn't seem to have changed much.
>
>
> Cheers, Phil.
>

(Also looking at the code) operator_array_proxy should be probably be
instantiated with the Reference, not ValueType...??? Would that be
correct? I.e., operator_array_proxy should wrap a reference (which is
not a real C++ reference), not a value...

You *could* just overload operator-> in the derived class to do
something else (in this case, I would say try using a proxy that wraps a
reference).

Also, just to be clear, the operator_array_proxy stuff in
iterator_facade fails not because std::pair< const KEY, VALUE& > isn't
convertible to std::pair< KEY, VALUE >, but because their pointers
aren't convertible. At least that's what I'm seeing...

Seems like I stumbled on this in the past and rather than figure out
what was wrong, I just redefined operator-> in the derived class to work...

- Jeff


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