vendredi 5 octobre 2018

Can I specialize a variadic template argument based on the signature of its operator()

Suppose I have a function like this

template <typename... FunctionList>
void call_all (int i, float f, const FunctionList... function_list);

template <>
void call_all (int, float)
{
}

I want to specialize it something like this:

template <typename HasIntArgument, typename... FL>
void call_all (int i, float f, const HasIntArgument & hia, const FL... list)
{
    hia (i);
    call_all (i, f, list...);
}

template <typename HasFloatArgument, typename... FL>
void call_all (int i, float f, const HasFloatArgument & hfa, const FL... list)
{
    hfa (f);
    call_all (i, f, list...);
}

In words, I want this function to, for each function-like object in function_list, determine whether it is callable with signature void(int) or void(float). (Nothing in this list will be callable with more than one signature.)

I want this to work with raw function pointers, lambdas, or anything with a suitable operator().

Can I write a suitable specialization directly, or do I have to do weird stuff with traits classes and SFINAE?

Aucun commentaire:

Enregistrer un commentaire