Search code examples
c++templatesvariadic-templates

variadic number of methods as template input parameter


Is it possible to specify a member-function template parameter pack? Something like this:

template <typename foo, void (foo::*bar)(void) ...>
void application()
{
}

None of my solutions work, and I would like to avoid putting every function that I'm gonna use in a struct.


Solution

  • The syntax for this is

    template <typename C, void (C::*...mfuncs)()>
    void application()
    {
        // ...
    }
    

    or with typedef:

    template <typename C>
    using MemberFunc = void (C::*)();
    
    template <typename C, MemberFunc<C>...mfuncs>
    void application();