Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-03-08 14:25:17


"Peter Dimov" <pdimov_at_[hidden]> writes:

> David Abrahams wrote:
>> Hi,
>>
>> I have this code that isn't compiling because of the "forwarding
>> problem" limitation of boost::bind:
>>
>> std::for_each(
>> make_difference_iterator(p->second.begin())
>> , make_difference_iterator(p->second.end())
>> , boost::bind(&fu::writeVInt, &prox, _1));
>
> Nice namespace name.

Name was changed to protect the innocent. It's a class name, really.

>> The problem is that an implicit conversion is required between the
>> reference type of the difference_iterator and the argument type of
>> writeVInt.
>>
>> It seems to me that, since I know that binding to an rvalue is
>> required, we ought to have a way to say "force this to be a const
>> ref". I thought of something like
>>
>> std::for_each(
>> make_difference_iterator(p->second.begin())
>> , make_difference_iterator(p->second.end())
>> , boost::bind(&fu::writeVInt, &prox, boost::cref(_1)));
>> ^^^^^^^^^^^^ ^
>>
>> I know it's not pretty, but it sorta does what we want. Thoughts?
>
> Have you tried to implement it? ;-)

'course not! ;-)

Is it hard?

> The current bind way to work around the above problem is to use an adaptor
> that fixes its signature to, for example, void(fu const &). Choices are
> function<void(fu const &)> and make_adaptable<void, fu const &> (in
> boost/bind/make_adaptable.hpp).

Huh! Where's make_adaptable documented?

> Lambda also provides its own mechanisms.

I'll look, thanks.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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