Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameter Pack Confusion

I just came across a very strange situation when writing a C++11 std::tuple-like class and trying to compile it with g++-4.7. What I basically need is a tuple of wrapped types. I wrote something like this:

#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; 
}

I made the following observations:

  1. The code does not compile:
  2. If I add (1), it does compile.
  3. If I remove (1) and (2), it does compile as well.

Error message for 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’

Question: In my opinion the code above is correct, but it is the first time that I actually use parameter packs. Are there any reasons that g++-4.7 does not like my code except for the fact that it is an experimental implementation?

like image 948
Markus Mayr Avatar asked Oct 21 '22 09:10

Markus Mayr


1 Answers

This is most likely a bug in g++ 4.7 that is fixed in g++ 4.8. Ideone (which uses g++ 4.7.2, and which I cannot link to without duplicating your code example, argh) gives the error you mention, whereas Coliru (using g++ 4.8) compiles without error.

like image 121
TemplateRex Avatar answered Nov 03 '22 01:11

TemplateRex