I've this template
template <typename T>
class Publisher
{
public:
Publisher(){}
~Publisher(){}
}
and I've this variadic template
template <typename First, typename... Rest>
class PublisherContainer
{
PublisherContainer();
~PublisherContainer();
}
In the PublisherContainer
constructor I want to create a Publisher
for every template argument:
template <typename First, typename... Rest>
PublisherContainer<First, Rest...>::PublisherContainer()
{
Publisher<First> publisher;
// create other publisher here.
}
So I can do
PublisherContainer<ClassA, ClassB, ClassC> myPublisher;
How can I invoke Publisher
for every template argument?
Class templates cannot have "pack members". Parameter packs must either be forwarded or unpacked; they cannot be used like types.
The easiest answer is to not reinvent the wheel and use the purpuse-built product type,
std::tuple
:(Note that "container" is probably a bad name, since in the idiom of standard C++, containers are things that model iterable ranges of elements. A tuple is a product ("one of each"), not a range. Maybe "PublisherHolder" is more appropriate, or drop the wrapper layer entirely and just use tuples directly.)