samedi 27 août 2016

C++ Expanding variadic template to a list of member functions error

I have the following piece of code that compiles successfuly in g++ 5.3, but fails with an odd error C2059: syntax error: '<tag>::*' when compiling it using Visual Studio 2015 C++ compiler (I am using from QtCreator and qmake).

I tried to google it, but didn't find anything related. Is it a Microsoft compiler bug, or there is something wrong with the code? I am restricted with this compiler, so if it is a some known bug, can it be avoided somehow?

#include <functional>
#include <tuple>

template<typename ItemT, typename... GetterRetTn>
class Test{
public:
    Test(GetterRetTn (ItemT::*... getters)() const) :
      m_attrs(getters...) {}

private:
    std::tuple<GetterRetTn (ItemT::*)() const ...> m_attrs; // fails here
};

struct test {
    int a;
    std::string s;

    int getA() const { return a; }
    std::string getS() const { return s; }
};

int main() {
    Test<test, int, std::string> model(&test::getA, &test::getS);

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire