C++ c++;模板包扩展/可变参数

C++ c++;模板包扩展/可变参数,c++,variadic-templates,C++,Variadic Templates,我有一个代码,它可以工作: auto thev = std::static_pointer_cast<Thevenin>( add(new Thevenin(N("cntl"), N("gnd"), 1.0))); auto det1 = std::static_pointer_cast<Detector>( add(new Detector(N("vout"), N("gnd"), N("eout"), N("oout"), 0))); auto det

我有一个代码,它可以工作:

auto thev = std::static_pointer_cast<Thevenin>(
    add(new Thevenin(N("cntl"), N("gnd"), 1.0)));
auto det1 = std::static_pointer_cast<Detector>(
    add(new Detector(N("vout"), N("gnd"), N("eout"), N("oout"), 0)));
auto det2 = std::static_pointer_cast<Detector>(
    add(new Detector(N("cntl"), N("gnd"), N("ein"),  N("oin"), 0)));
不幸的是,关于包扩展的文档对我来说太简洁了,我无法编写一个将要编译的tfun模板。有人能告诉我是怎么做的吗?

看起来很琐碎

template<class RetVal, class... Args> inline auto tfun(Args &&...args) {
     return std::static_pointer_cast<RetVal>(add(new RetVal(std::forward<Args>(args)...)));
}

auto thev = tfun<Thevenin>(N("cntl"), N("gnd"), 1.0);
模板内联自动tfun(Args&&…Args){
返回std::static_pointer_cast(添加(新的RetVal(std::forward(args)…));
}
自动推力=tfun(N(“cntl”)、N(“gnd”)、1.0;
看起来微不足道

template<class RetVal, class... Args> inline auto tfun(Args &&...args) {
     return std::static_pointer_cast<RetVal>(add(new RetVal(std::forward<Args>(args)...)));
}

auto thev = tfun<Thevenin>(N("cntl"), N("gnd"), 1.0);
模板内联自动tfun(Args&&…Args){
返回std::static_pointer_cast(添加(新的RetVal(std::forward(args)…));
}
自动推力=tfun(N(“cntl”)、N(“gnd”)、1.0;

Make
add
一个类似于
std::Make_unique的模板
你想实现什么?也许你想使用符合你需要的
make_shared
?在您的案例中,
add
是什么?您可以查看
make{shared|unique}
是如何实现的,以了解如何实现您想要的功能;事实上,你需要一个静态的ptr转换,这是你最大的问题。让
添加
一个类似于
std::Make_unique
的模板,你想实现什么?也许你想使用符合你需要的
make_shared
?在您的案例中,
add
是什么?您可以查看
make{shared|unique}
是如何实现的,以了解如何实现您想要的功能;事实上,你需要一个静态的ptr演员有你的大部分问题。