In cminpack, two types of function pointer are used. For example, as for hybrd, we could pass a function pointer to it, which is like
void(*fun)(const int *n, const real *x, real *fvec, int *iflag) or int (*fun)(void *p, int n, const real *x, real *fvec, int iflag). The void *p in the latter type is used to pass additional parameters without using global variables.
But if we want to use lambda, functor, or something else, we cannot make it. So, why not use some templates, so that we are not only able to pass a static type function pointer to hybrd, but also lambda, functor or other stuff.
In cminpack, two types of function pointer are used. For example, as for
hybrd, we could pass a function pointer to it, which is likevoid(*fun)(const int *n, const real *x, real *fvec, int *iflag)orint (*fun)(void *p, int n, const real *x, real *fvec, int iflag). Thevoid *pin the latter type is used to pass additional parameters without using global variables.But if we want to use lambda, functor, or something else, we cannot make it. So, why not use some templates, so that we are not only able to pass a static type function pointer to
hybrd, but also lambda, functor or other stuff.