[英]using declaration of a specialized variadic template class
Is it possible to define FloatType
in such a way that I can declare a f1
as 是否可以以这样的方式定义
FloatType
,即可以将f1
声明为
FloatType f1;
instead of 代替
FloatType<> f1;
If i try to use the former i get a 如果我尝试使用前者,我会得到一个
error: use of class template 'FloatType' requires template arguments
template <typename T, typename... Args>
class Type
{
};
template <typename... Args>
class Type<float, Args...>
{
};
template <typename... Args>
using FloatType = Type<float, Args...>;
int
main(int, char **)
{
FloatType<> f1;
FloatType<float> f2;
return 0;
}
No, that is impossible. 不,那是不可能的。 From the standard §14.3/4, emphasis mine:
根据标准§14.3/ 4,请强调:
When template argument packs or default template-arguments are used, a template-argument list can be empty.
使用模板参数包或默认模板参数时 , 模板参数列表可以为空。 In that case the empty
<>
brackets shall still be used as the template-argument-list .在那种情况下,空的
<>
括号仍应用作template-argument-list 。 [ Example:[示例:
template <class T = char> class String; String<>* p; // OK: String<char> String* q; // syntax error template <class ... Elements> class Tuple; Tuple<>* t; // OK: Elements is empty Tuple* u; // syntax error
—end example ]
—末例]
But then, what's wrong with writing FloatType<>
? 但是,编写
FloatType<>
什么问题呢? If seeing the empty brackes really irks you, you can introduce another alias for them, but that kind of obfuscates things: 如果看到空括号确实让您感到讨厌,则可以为它们引入另一个别名,但这种方法会使您感到困惑:
using DefFloatType = FloatType<>;
Plus, it's more typing! 此外,还有更多输入内容!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.