I have a family of functions {f_n}
where f_0
is continuous, f_1
is continuously differentiable, $f_{n} \in C^{n}[a,b]$ so on. I have a C++ class which gives a numerical evaluation of f_n
via a lookup table on a vector v
template<int n, typename Real=double>
class f
{
public:
f() { /* initialize v */ }
Real operator()(Real x) { /* find appropriate index for x, and interpolate */}
private:
std::vector<Real> v;
};
However, if f
is differentiable (n >= 1
), I want to add a member function:
template<int n, typename Real=double>
class f
{
public:
f() { /* initialize v and dv */ }
Real operator()(Real x) { /* find appropriate index for x, and interpolate on v */}
Real prime(Real x) { /* find appropriate index for x, and interpolate on dv */}
private:
std::vector<Real> v;
std::vector<Real> dv;
};
I would also like to add a second derivative member for n >= 2, so on. Can this be done in a single class? (C++17 syntax is acceptable for me.)
n
to be larger or equal to1
? Is this supposed to be a non type template parameter? – Reeceint n
. – Vidovik