用户定义的可变字符模板文字
最近,在 gcc-trunk 源中实现了“用户定义的文字”。 请告诉我,我是否正确理解我无法为可变字符模板定义“用户定义的文字”?
template<char... chars>
int operator"" _call() { return sizeof...(chars); }
...
std::cout << "method"_call;
向上。
我不明白为什么允许这个表达式:
template<char... chars>
int operator"" _call() { return sizeof...(chars); }
...
std::cout << 12345566_call;
而不允许这个表达式:
template<char... chars>
int operator"" _call() { return sizeof...(chars); }
...
std::cout << method_call;
?
有什么意义?
向上。 这是因为歧义吗?
谢谢。
Recently, in the gcc-trunk sources was implemented the "user defined literals".
Tell me please, do I understand correctly that I can`t define a "user defined literals" for variadic char template?
template<char... chars>
int operator"" _call() { return sizeof...(chars); }
...
std::cout << "method"_call;
Up.
I don`t understand why this expression is allowed:
template<char... chars>
int operator"" _call() { return sizeof...(chars); }
...
std::cout << 12345566_call;
and this one is disallowed:
template<char... chars>
int operator"" _call() { return sizeof...(chars); }
...
std::cout << method_call;
?
What's the point?
Up.
this is because of the ambiguity?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,这确实没有意义。字符串文字作为两个参数传递给
operator""
,其中之一是大小,所以您想要的是:标准报价时间 (2.14.8.5):
可变参数模板形式仅考虑用于用户定义的整数文字(2.14.8.3)和用户定义的浮动文字< /em> (2.14.8.4)。
至于
method_call
,method
不是文字。No, it doesn't really make sense. String literals are passed as two arguments to
operator""
, and one of them is size, so what you want is:Standard quote time (2.14.8.5):
The variadic template forms are considered only for user-defined-integer-literal (2.14.8.3) and user-defined-floating-literal (2.14.8.4).
As for
method_call
,method
is not a literal.method_call
是一个有效的标识符,例如some_call
或my_call
。现在想象一下,如果允许operator""
重新定义此类标识符,将会破坏多少代码。method_call
is a valid identifier As is for examplesome_call
ormy_call
. Now imagine how much code would be broken if such identifiers were allowed to be redefined byoperator""
.