Problem working with C++11 Parameter Pack Expansion

Hello,

I am facing a problem with C++11 parameter pack expansion. I have code somewhat like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <tuple>


typedef struct {
	typedef int Type1;
	typedef int Type2;
} CaseA;

typedef struct {
	typedef int Type1;
	typedef int Type2;
} CaseB;

template <typename... Ts>
class MultiCase {
public:
	using Type1 = std::tuple<Ts::Type1...>;
	using Type2 = std::tuple<Ts::Type2...>;
};

int main()
{	
	MultiCase<CaseA,CaseB>::Type1 test;
	
	return 0;
}


The error is as follows:

test.cpp:18:39: error: type/value mismatch at argument 1 in template parameter list for ‘template<class ... _Elements> class std::tuple’
  using Type1 = std::tuple<Ts::Type1...>;
                                       ^
test.cpp:18:39: note:   expected a type, got ‘Ts::Type1 ...’
test.cpp:19:39: error: type/value mismatch at argument 1 in template parameter list for ‘template<class ... _Elements> class std::tuple’
  using Type2 = std::tuple<Ts::Type2...>;
                                       ^
test.cpp:19:39: note:   expected a type, got ‘Ts::Type2 ...’
test.cpp: In function ‘int main()’:
test.cpp:24:26: error: ‘Type1’ is not a member of ‘MultiCase<CaseA, CaseB>’
  MultiCase<CaseA,CaseB>::Type1 test;
                          ^~~~~


The expansion does not work. What I would like to get is an expansion to std::tuple<CaseA::Type1,CaseB::Type1> and std::tuple<CaseA::Type2,CaseB::Type2>. What am I doing wrong?

Thank you in advance,
best regards,
Ralf
Last edited on
Those are dependent names.
18
19
	using Type1 = std::tuple<typename Ts::Type1...>;
	using Type2 = std::tuple<typename Ts::Type2...>;


24
25
	typename MultiCase<CaseA,CaseB>::Type1 test;

See: http://coliru.stacked-crooked.com/a/897a52a394a8779d

Where and why do I have to put the “template” and “typename” keywords?
https://stackoverflow.com/q/610245/2085046

P.S.: You need not typedef structures in C++. C++ does not distinguish tag names.
Last edited on
Thank you very much for both the solution and the stack overflow resource!
Topic archived. No new replies allowed.