How to create a template with variable number of type parameters?

407 views Asked by At

In our codebase we use std::variant<std::shared_ptr<SomeClass>, ...> a lot.

That obviously requires a lot of writing. How to make a template?

template <class... T>
using VarSP = std::variant<std::shared_ptr<???>>;

Where should T go in the above snippet? The desired behavior should be:

VarSP<Foo, Bar, Baz> // std::variant<std::shared_ptr<Foo>, std::shared_ptr<Bar>, std::shared_ptr<Baz>>
1

There are 1 answers

0
user7860670 On BEST ANSWER
template <typename... T>
using VarSP = std::variant<std::shared_ptr<T>...>;