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)
, it does compile.(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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With