S
StephQ
I'm writing some algorithms that works on generic functions using
boost::bind.
My problem is that class templates can never be deduced.
In the simplest cases I just write the class like:
class Legendre
{
....
public:
template<class F>
static double computeIntegral( const F& f );
}
double value = Legendre::computeIntegral(boost::bind( &Sde::drift,
&sde, _1 ));
However in more complext examples, I have to work with classes with
non static memeber fucntions.
For example becouse I need to store data previously calculated about
the function for efficecny reasons.
I would like to "fix" the F at the moment of the construction of the
class and then invoke member functions of the class to perform
operations.
That is I would like to being able to do something like:
template<class F>
class FunctionAnalysis
{
private:
F& function;
public:
FunctionAnalysis( const F& f );
double operation1();
double operation2();
}
template<class F>
FunctionAnalysis<F>::FunctionAnalysis( const F& f)
:
function(f)
{}
FunctionAnalysis driftAnalysis(boost::bind( &Sde::drift, &sde, _1 ));
double x = driftAnalysis.operation1();
double y = driftAnalysis.operation2();
There are two problems:
1) I class template arguments can never be deduced
2) driftAnalysis is not of type FunctionAnalysis
I can solve the fist problem using the same approach of make_pair, but
I dont't see any way to solve th second problem.
The objective is to avoid having to specify the template parameter of
the class (and using boos::bind you can easily see why ).
Do you have any suggestion?
Thank you!
Cheers
StephQ
boost::bind.
My problem is that class templates can never be deduced.
In the simplest cases I just write the class like:
class Legendre
{
....
public:
template<class F>
static double computeIntegral( const F& f );
}
double value = Legendre::computeIntegral(boost::bind( &Sde::drift,
&sde, _1 ));
However in more complext examples, I have to work with classes with
non static memeber fucntions.
For example becouse I need to store data previously calculated about
the function for efficecny reasons.
I would like to "fix" the F at the moment of the construction of the
class and then invoke member functions of the class to perform
operations.
That is I would like to being able to do something like:
template<class F>
class FunctionAnalysis
{
private:
F& function;
public:
FunctionAnalysis( const F& f );
double operation1();
double operation2();
}
template<class F>
FunctionAnalysis<F>::FunctionAnalysis( const F& f)
:
function(f)
{}
FunctionAnalysis driftAnalysis(boost::bind( &Sde::drift, &sde, _1 ));
double x = driftAnalysis.operation1();
double y = driftAnalysis.operation2();
There are two problems:
1) I class template arguments can never be deduced
2) driftAnalysis is not of type FunctionAnalysis
I can solve the fist problem using the same approach of make_pair, but
I dont't see any way to solve th second problem.
The objective is to avoid having to specify the template parameter of
the class (and using boos::bind you can easily see why ).
Do you have any suggestion?
Thank you!
Cheers
StephQ