samedi 24 mars 2018

Member function pointer wrapper using variadic template (gcc, clang)

Why does the following code not compile under either gcc or clang:

class Foo {
public:
    void bar(int) {}
};

template< class T, typename ...Args, void(T::*Member)(Args...) >
void member_dispatch(Args&&... args, void* userdata)
{
    T* obj = static_cast<T*>(userdata);
    (obj->*Member)(std::forward<Args>(args)...);
}

int main()
{
    Foo foo;
    member_dispatch<Foo, int, &Foo::bar>(1, &foo);
    return 0;
}

See e.g. here.

This question can possibly be merged with this one, though here I get unclear compilation errors from gcc and clang (instead of VS).

Aucun commentaire:

Enregistrer un commentaire