Boris Sargos wrote:
Hi,
suppose we have these two functions (not very interesting, but this is for
clarity) :
-) a function Primitive that computes at t the primitive of a function
f :
double Primitive ( double(*f)(double), t);
I haven't done much maths in French but I think I "primitive" means
antiderivative. In that case your description of this function is
nonsense.
-) a function Indicatrice that defines if the parameter t is in the
interval [i, i+1] :
double Indicatrice ( int, double );
The characteristic function of the interval.
I'd like to write a function Indicatrice_i, restriction of Indicatrice to
i, like this :
double (*Indicatrice_i)(double) = Indicatrice(i);
to use it such this manner :
for(int i ...;;) {
// Computation of the primitive at t
double It = Primitive ( Indicatrice_i , t );
}
Someone could help ?
Identifiers do not work like that.
You could use "std::bind1st (std::ptr_fun (Indicatrice), i)". The type
of that expression is complicated so (a) it's not straightforward to
give the function object a name, and (b) you have to modify Primitive to
accept function objects of any appropriate type.
#include <functional>
#include <limits>
#include <iostream>
template <typename F> double Primitive (F f, double t)
{
// Note: here the function object has a name.
return std::numeric_limits <double>::quiet_NaN ();
}
double Indicatrice (int i, double t)
{
return i <= t && t <= i + 1 ? 1.0 : 0.0;
}
int main ()
{
double t = 0.0;
for (int i = 0; i != 10; ++ i)
{
using std::bind1st;
using std::ptr_fun;
std::cout << Primitive (bind1st (ptr_fun (Indicatrice), i), t)
<< '\n';
}
}
--
Regards,
Buster.