[英]Referring to template parameter pack in class
从C ++ 17开始,我们有了可选的模板参数包。 但是我怎么在课堂上提到这个呢? 有谁有很好的榜样吗? 谢谢!
https://gcc.godbolt.org/z/485Z0J
template<auto...>
struct C { };
int main()
{
C<'C', 0, 2L, nullptr> x;
return 0;
}
https://en.cppreference.com/w/cpp/language/template_parameters
首先是一些术语。 那不是“可选模板参数包”。 那是带有auto的可变参数非类型模板参数。
有几种引用它们的方法,但是您需要给可变参数一个名称。 这里有些例子:
#include <tuple>
template <class... Args>
auto foo(Args...) -> void;
template<auto... Args>
struct C
{
static constexpr std::tuple<decltype(Args)...> t{Args...};
auto call_foo()
{
foo(Args...);
}
};
auto test()
{
C<'C', 0, 2L, nullptr> x;
x.call_foo();
return std::get<2>(x.t);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.