mardi 3 novembre 2015

C++ variadic class templates and member functions

I'm having problems working around a problem in the following code...

#include <functional>

template<typename... ARGS>
class MyClass {
public :
    void function(ARGS... args)
    {
    }
};

int main(int argc, char * argv[])
{
    MyClass<int>        myClassInt;      // works fine
    MyClass<int, float> myClassIntFloat; // works fine
    MyClass<void>       myClassVoid;     // <---- won't compile

    return 0;
}

Clang quite rightly refusing to compile this if I instantiate MyClass on void, complaining that MyClass<void>::function is not a legal definition. However the real class I have needs to be able to instantiate this kind of thing on a void. I've been staring at this for ages and I'm stuck as to what template SFINAE jiggery-pokery I need to get around it.

Aucun commentaire:

Enregistrer un commentaire