I recently saw this in production code and couldn't quite figure out what it does:
template <class... Ts>
struct pool : pool_type<Ts>... {
//...
};
I've never seen pack expansion happening for parent classes. Does it just inherit every type passed into the varargs?
The parents look like this:
template <class T>
struct pool_type : pool_type_impl<T> {
// ...
};
Yes. It inherits publicly from each of the passed arguments. A simplified version is given below.
From Parameter pack's documentation:
Example
The output of the above program can be seen here:
Explanation
In the above code, the
X
class template uses a pack expansion to take each of the supplied mixins and expand it into a public base class. In other words, we get a list of base classes from whichX
inherits publicly. Moreover, we also have aX
constructor that copy-initializes each of the mixins from supplied constructor arguments.