-
January 28th, 2014, 05:43 PM
#1
Variadic templates and type composition
Here's an interesting question I encountered. This isn't critical, but it would be "cool" to know how to accomplish it....
Let's say I have a variadic type A and a non-variadic type B:
Code:
template <typename ... Args>
class A
{};
template <typename T>
class B
{};
Now, I'd like to do the following (pseudocode since I don't know how to do this yet):
Code:
template <typename ... Args>
class C: public A<B<Args1>,B<Args2>,B<Args3>....>
{};
Essentially, I'd like to take the parameter pack used for C and compose B around each element individually, then pass the result to A.
Any idea how I can do this?
-
January 29th, 2014, 03:16 AM
#2
Re: Variadic templates and type composition
Code:
template <typename... Args>
class C: public A<B<Args>...>
{};
when appearing where a parameter pack can be used ( and in other contexts too ), packs expansions ( eg, an expression E followed by an "..." ) will expand into a parameter pack E1,E2,.. where Ei is the expression E where any parameter pack "...P" appearing in it is replaced with its ith element Pi.
-
January 30th, 2014, 10:59 AM
#3
Re: Variadic templates and type composition
Thanks, that's exactly what I needed!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|