Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11: What's the difference between "parameter pack" and "variadic template"?

Seen from the introduction http://en.cppreference.com/w/cpp/language/parameter_pack, seems the concept of "parameter pack" is something the same as "variadic template". So what's the conceptual difference between them?

Thanks!

like image 562
Troskyvs Avatar asked Nov 17 '25 06:11

Troskyvs


1 Answers

Syntactically, parameter pack is a part of a variadic template. For example,

template<class ... Types> struct Tuple {};

is a variadic structure template, and Types is a parameter pack in it. Tuple itself is not a parameter pack.

You may pass any set of type parameters to Tuple, and they will be packed to Types pack. For example in the code

Tuple<int, float, std::string> foo;

we instantiated a Tuple template with int, float and string types and got a structure of actual type Tuple<int, float, std::string>. The code of Tuple may now expand Types pack.

like image 51
Sergey Avatar answered Nov 20 '25 05:11

Sergey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!