简体   繁体   中英

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

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>>
template <typename... T>
using VarSP = std::variant<std::shared_ptr<T>...>;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM