Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2004-12-05 23:42:52


Duane Murphy wrote:
> --- At Sun, 5 Dec 2004 07:34:38 -0500, David Abrahams wrote:
>

>>>>>Sorry, I can't imagine what you mean. Of course bind works with
>>>>>non-const return types: [...]
>>>>
>>>>Probably the following:
>>>>
>>>> std::for_each( first, last, boost::bind( f, _1 ) );
>>>>
>>>>When *first returns a non-const rvalue, bind can't take it.
>
>
> Bingo! This is the exact case that I am trying to test.
>
>
>>>I guess the answer is to make the reference type const, then.

Well really the answer is to fix bind so that it works with rvalues, at
least for a few arguments.

>>That will suppress the iterator's writability, though. I hope it's desired.
>
>
> No, it's not really.
>
> I was hoping for some kind of proxy interface where a const proxy could
> be return and dereferencing the proxy would return the object.
>
> Maybe holding the current value in the iterator is the correct solution.

You can always reimplement operator* in your derived iterator:

   reference const operator*() const { return this->dereference(); }

HTH,

-- 
Dave Abrahams
Boost Consulting
http://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