dimanche 6 octobre 2019

Initialize tuple with class templated on each type of variadic template

The title is probably hard to parse so here's what I mean. Let's say I have a few classes A, B1, B2, B3... Bn where I'd like to hold a tuple of A's templated on some B class. A valid final result could be something like tuple<A<B3>, A<B1>> _chain. This would be contained within a container class we'll call C. What I'm looking for is to initialize C with a bunch of B types that then get wrapped in my A class. I can't simply do

template<class... T>
class C
{
    std::tuple<T...> _chain;
public:
    C(const T&... t) : _chain(t...) { }
};

because then I'd end up with a tuple of Bs. Is there an ergonomic way to wrap the init step (_chain(t...)) so that I'll end up with a tuple of A's templated on the B classes I pass to the class?

Aucun commentaire:

Enregistrer un commentaire