Consider the following pseudo code :
template<class... T>
struct worker : unique<T...>::type...{};
struct x{};
struct y{};
struct z{};
Is it possible to write a template unique
such that it generates a parameter pack consisting of only unique types among T
s, so that worker<x,y,x,z>
will be directly derived from x
, y
, z
respectively ,in that order, given T
s are non final classes?
Parameter packs (C++11) A parameter pack can be a type of parameter for templates. Unlike previous parameters, which can only bind to a single argument, a parameter pack can pack multiple parameters into a single parameter by placing an ellipsis to the left of the parameter name.
A variadic template is a class or function template that supports an arbitrary number of arguments. This mechanism is especially useful to C++ library developers: You can apply it to both class templates and function templates, and thereby provide a wide range of type-safe and non-trivial functionality and flexibility.
AFAIK: No.
The problem is that type
is the result of a typedef
directive, and typedef
cannot alias packs. It is actually a bother, and most often computations on packs require introducing a wrapper type (such as template <typename...> struct pack {};
) just to be able to pass them around.
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