
Boost Users : 
Subject: Re: [Boostusers] [lamda] smart self binding of a function object
From: alfC (alfredo.correa_at_[hidden])
Date: 20100602 17:53:46
On May 27, 12:25 am, alfC <alfredo.cor..._at_[hidden]> wrote:
> This is simplest still useful solution I found. I realized that
> returning function<double(double)> would defeat the purpose since it
> is not a lambda expression an I would need bind again to insert it in
> a lambda expression
>
> this is the soltution
(see code in previous post)
this is the generalization to function objects that take *two*
arguments,
note that there are two template parameters now.
As you see the code is still quite long, I didn't find a way to
simplify it.
(I still didn't manage to use CRTP for example.)
class A{
typedef A self_type;
...
complex operator()(quantity<atomic::wavenumber> const& k,
quantity<atomic::frequency> const& w) const{
//function that does the real work ...
}
template<class LambdaExp1, class LambdaExp2>
lambda_functor<lambda_functor_base<
action<4,
function_action<4>
>,
tuple<
//signature of function that does the real work
complex(self_type::* const)(quantity<atomic::wavenumber> const&,
quantity<atomic::frequency> const&) const,
const self_type,
lambda_functor<LambdaExp1> const,
lambda_functor<LambdaExp2> const
>
> > operator()(lambda_functor<LambdaExp1> const& exp1,
lambda_functor<LambdaExp2> const& exp2) const{
return bind(
//signature is repeated here
static_cast<complex(self_type::* const)(quantity<atomic::wavenumber>
const&, quantity<atomic::frequency> const&)
const>(&self_type::operator()),
static_cast<self_type const&>(*this), //static_cast not necesary
until we manage to put this in CRTP base class
exp1,
exp2);
}
};
Boostusers 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