简体   繁体   中英

How to specialize a class template for a tuple by using variadic template arguments?

How to specialize a class template for a tuple? I try the following but failed. I am using VC Compiler Nov 2012 CTP which support variadic template arguments.

template<class T>
struct A
{
   void f() {}
};

template<class... Args>
struct A<tuple<Args...>>
{
   void g() {}
};

I try

A<tuple<int, float>> a;
a.g(); // error error C2039: 'g' : is not a member of 
//'A<std::tuple<int,float,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil>>

Thanks to yngum. It might be a VC compiler bug. If so, how to work around?

This is a compiler-bug. As a work-around, simply add the 2-parameter specialization

template<class Arg0, class Arg1>
struct A< std::tuple<Arg0, Arg1> >
{
   void g() {}
};

Live Example .

Yes, you'll have to do this for as many parameters as your code is likely to use. Or, you could try VS 2013 RC which is likely to have fixed this bug.

Update : I now see that you asked a separate question about the work-arounds. The same solution was posted there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM