Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to generate a parameter pack?

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 Ts, so that worker<x,y,x,z> will be directly derived from x, y, z respectively ,in that order, given Ts are non final classes?

like image 371
user1436623 Avatar asked Jun 05 '12 06:06

user1436623


People also ask

What is a parameter pack?

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.

What is a variadic template C++?

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.


1 Answers

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.

like image 139
Matthieu M. Avatar answered Sep 17 '22 13:09

Matthieu M.