|
Boost Users : |
Subject: Re: [Boost-users] [lambda] How to write a lambda functor that returns a new functor
From: Sebastian Theophil (stheophil_at_[hidden])
Date: 2011-03-10 05:12:30
Steven,
>
> On 03/09/2011 06:11 AM, Sebastian Theophil wrote:
> > How can I write a lambda expression with two placeholders, one for
the
> > callable object, and one for the function argument, such that
> > supplying the callable object first returns a unary function?
>
> In this case, boost::lambda::_1 by itself does what you want, because
the
> callable object itself is a unary function.
That is true of course, I was trying to solve a slightly more
complicated problem though. I have solved the problem finally, although
I hoped there was a more elegant solution:
struct FCreateBind {
typedef boost::_bi::bind_t<bool, Callable,
boost::_bi::list2<boost::arg<1>, boost::arg<2> > > result_type;
result_type operator()( Callable const& c ) const {
return boost::bind<bool>(c, _1);
}
};
BOOST_AUTO(generate, boost::bind(FCreateBind(), _1));
BOOST_AUTO(fn, generate(Callable());
bool b = fn(Arg());
Of course, in this simple example I could just write
BOOST_AUTO(generate, boost::lambda::_1) since Callable itself is the
callable object. But I was looking for a way to set the arguments of
Callable beforehand so the generated function fn is a nullary function.
This solution would let me do this inside FCreateBind.
FCreateBind can probably be eliminated as well, but I have not yet
figured out how to define the pointer to the overloaded global function
boost::bind.
Regards
Sebastian
-- Sebastian Theophil | stheophil_at_[hidden] Senior Software Engineer think-cell Software GmbH | Chausseestr. 8/E | 10115 Berlin | Germany http://www.think-cell.com | phone +49 30 666473-10 | US phone +1 800 891 8091 Amtsgericht Berlin-Charlottenburg, HRB 85229 | European Union VAT Id DE813474306 Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl
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