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::compu teIntegral(boos t::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 FunctionAnalysi s
{
private:
F& function;
public:
FunctionAnalysi s( const F& f );
double operation1();
double operation2();
}
template<class F>
FunctionAnalysi s<F>::FunctionA nalysis( const F& f)
:
function(f)
{}
FunctionAnalysi s driftAnalysis(b oost::bind( &Sde::drift, &sde, _1 ));
double x = driftAnalysis.o peration1();
double y = driftAnalysis.o peration2();
There are two problems:
1) I class template arguments can never be deduced
2) driftAnalysis is not of type FunctionAnalysi s
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 :D ).
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::compu teIntegral(boos t::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 FunctionAnalysi s
{
private:
F& function;
public:
FunctionAnalysi s( const F& f );
double operation1();
double operation2();
}
template<class F>
FunctionAnalysi s<F>::FunctionA nalysis( const F& f)
:
function(f)
{}
FunctionAnalysi s driftAnalysis(b oost::bind( &Sde::drift, &sde, _1 ));
double x = driftAnalysis.o peration1();
double y = driftAnalysis.o peration2();
There are two problems:
1) I class template arguments can never be deduced
2) driftAnalysis is not of type FunctionAnalysi s
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 :D ).
Do you have any suggestion?
Thank you!
Cheers
StephQ
Comment