How to make a Variadic method of a template class take a function pointer as an argument with a type derived from a function template?

Sorry, the name is a sip. I am working on an array class similar to that described here . I want to define a map function that accepts a user-defined function and applies it to each element of the array. For the purpose of type checking, I would like to define it so that the function specified by the user should take the same number of arguments that are passed to the map function, so

double f(double a, double b) { return a + b; }
Array<double,2> x, y, z; x.map(f, y, z);

will compile but

double g(double a, double b, double c) { return a + b + c; }
Array<double,2> x, y, z;. x.map(g, y, z);

will not, because it gtakes the wrong number of arguments based on what was passed to the map function.

I tried syntax like:

template<typename T, size_t ... Ns> class Array
{
    template<class ... Args> inline const Array<T, Ns...>
        map(T (*fn)(decltype(Args, double)...), Args...)
    {
        // doesn't compile
    }
}

, , , . .

+4
1
template <typename T, std::size_t ... Ns>
struct Array
{
    template <typename>
    using arg_type = T;

    template <class ... Args>
    Array<T, Ns...> map(T (*fn)(arg_type<Args>...), Args...)
    {
        return {};
    }
};

DEMO

+3

All Articles