参数包混乱

Mar*_*ayr 5 c++ tuples g++ variadic-templates c++11

在编写类似C++11 std::tuple的类并尝试使用它编译时,我遇到了一个非常奇怪的情况g++-4.7.我基本上需要的是一个包裹类型的元组.我写了这样的东西:

#include <tuple> 

template <class T> 
struct Wrapper { T x; }; 

template <class... Types> 
using Tuple = std::tuple<Wrapper<Types>...>; 

template <class... Types> 
struct X 
{ 
    using MyTuple = Tuple<Types...>; 
}; 

int main( int argc, char** argv ) 
{ 
    // Tuple<int,int> t;  // (1)
    using Y = X<int,int>;
    Y y;                  // (2)
    return 0; 
}
Run Code Online (Sandbox Code Playgroud)

我做了以下观察:

  1. 代码无法编译:
  2. 如果我添加(1),它会编译.
  3. 如果我删除(1)(2),它编译为好.

1的错误消息:

test.cpp: In instantiation of ‘struct X<int, int>’:
test.cpp:22:4:   required from here
test.cpp:10:44: error: wrong number of template arguments (2, should be 1)
test.cpp:4:8: error: provided for ‘template<class T> struct Wrapper’
Run Code Online (Sandbox Code Playgroud)

问题:在我看来,上面的代码是正确的,但这是我第一次真正使用参数包.有没有什么理由g++-4.7不喜欢我的代码,除了它是一个实验性的实现?

Tem*_*Rex 3

这很可能是g++ 4.7 中的错误,已在 g++ 4.8 中修复。Ideone(使用 g++ 4.7.2,我无法在不复制您的代码示例的情况下链接到它,argh)给出您提到的错误,而Coliru(使用 g++ 4.8)编译时没有错误。