lundi 8 octobre 2018

template alias for function with varying number of arguments

I have a class template Foo which has several members, one of which is a function bar of type Bar:

template<std::size_t N>
class Foo
{
    ...
    Bar<N> bar;
    ...
};

I would like Bar<2> to be a template alias for a function double (* )(double, double) (or possibly std::function<double(double, double)>). Similarly, I want Bar<3> to be a template alias for a function double (* )(double, double, double) (or possibly std::function<double(double, double, double)>). This means that N should specify the number of double arguments that the function bar takes.

The only way I managed to get anywhere close to this behaviour, is by using the template alias

template <std::size_t N>
using Bar = double (* )(std::array<double, N>& eval);

In this way, however, I can not call the function bar in its natural way bar(x,y,z).

Is it possible to get the behaviour that I want?

Aucun commentaire:

Enregistrer un commentaire