Boost logo

Boost :

Subject: Re: [boost] [Bind] How do I get bind to deduce the return type of for_each?
From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2010-04-17 08:30:50


On Sat, Apr 17, 2010 at 7:25 AM, Roland Bock <rbock_at_[hidden]> wrote:
> Thomas Jordan wrote:
>>
>> [snip]
>> Thanks for the suggestion, Roland, I am sure you could get something like
>> this to work easily enough.  However, if I understand correctly your
>> suggestion involves defining a separate functor  - myClass - to take the
>> vocType's, and which I guess wraps the inner call to for_each.  I had hoped
>> for a more generic solution which doesn't involve the creation of new
>> functors.  I was hoping I could accomplish the objective of passing an
>> algorithm into an algorithm jgenerically, just doing everything at point of
>> call using just Boost.bind, the std::algorithms (wrapped) and using if
>> necessary some boost.function functors to help type deduction.  Are we
>> saying this isn't possible?
>>
>
> Hi Thomas,
>
> we don't say it isn't possible :-)
>
> Here you go:
>
<snip>
>
>  for_each(vov.begin(), vov.end(),
>        bind(for_each< vocType::iterator, function<void (myClass&)> >,
>           bind<vocType::iterator>(&vocType::begin, _1),
>           bind<vocType::iterator>(&vocType::end, _1),
>           protect(bind(&myClass::func, _1))
>           )
>        );

Oh yeah, that's a good idea! Instantiate std::for_each with a void
boost::function! That's a portable solution as well, since bind and
function are available on practically any compiler, even ancient,
substandard ones.

Daniel Walker


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