简体   繁体   English

如何创建具有可变数量类型参数的模板?

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

In our codebase we use std::variant<std::shared_ptr<SomeClass>, ...> a lot. 在我们的代码库中,我们使用std::variant<std::shared_ptr<SomeClass>, ...>

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? T应该放在上面的代码段中? 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>...>;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何迭代可变参数模板参数来创建可变数量的局部变量? - How to iterate through variadic template parameters to create variable number of local variables? 如何在容器和类型均为参数的情况下创建模板函数? - How create template functions where both the container and the type are parameters? 可变数量的构造函数参数取决于整数模板 - Variable number of constructor parameters depending on integer template 我需要一个带有可变数量参数的模板功能 - I need a template function with a variable number of parameters 有没有办法在模板类中处理可变数量的参数? - Is there a way to handle a variable number of parameters in a template class? 具有可变数量的模板参数的简单方法 - Simple way to have variable number of template parameters C ++可变数目的可变参数模板参数 - C++ Variable number of variadic template parameters 如何将可变数量和参数类型传递给模板函数? - How to pass a variable number and type of arguments to template function? 如何减少模板模板参数的参数 - How to reduce a number of parameters of a template template parameter 如何使用两个模板模板参数指定共享模板变量? - How to specify shared template variable with two template template parameters?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM