[英]Does C++17 allow a non-ascii character as an identifier?
At cppref , I find a strange C++ code, which uses a non-ascii character in source code as follows: 在cppref ,我找到一个奇怪的C ++代码,它在源代码中使用非ascii字符,如下所示:
template <char...> double operator "" _π(); // OK
However, the code above cannot be cmompiled with clang 6.0. 但是,上面的代码不能用clang 6.0进行编译。 The error message is: 错误消息是:
error : source file is not valid UTF-8
1>double operator "" _<A6><D0>()
1> ^
My questions are: 我的问题是:
_π
has no argument, then, how to use _π
? 注意用户定义的_π
没有参数,那么,如何使用_π
? Just use double var = _π;
只需使用double var = _π;
? ? From the link you provided, it quotes: 从您提供的链接,它引用:
If the literal operator is a template, it must have an empty parameter list and can have only one template parameter, which must be a non-type template parameter pack with element type char 如果文字运算符是模板,则它必须具有空参数列表,并且只能有一个模板参数,该参数必须是元素类型为char的非类型模板参数包
template <char...> double operator "" _x();
Let us see what this means, 让我们看看这意味着什么,
Notation char...
indicates that this template can be instantiated with 0, 1, 2 or more parameters of type char
. 符号char...
表示此模板可以使用0,1,2或更多char
类型的参数进行实例化。 This means that each time the compiler encounters a literal like 1234_km
it should treat it as the following function call: 这意味着每次编译器遇到像1234_km
这样的文字时,都应将其视为以下函数调用:
operator"" _km<'1', '2', '3', '4'>();
The entire string representing the literal is passed (chopped) as template argument. 表示文字的整个字符串作为模板参数传递(切断)。 See this and this for usage. 请参阅此以及此用途。
And regarding the range of characters allowed:(See this Annexure E ) 关于允许的字符范围:(见附件E )
00A8, 00AA, 00AD, 00AF, 00B2-00B5, 00B7-00BA, 00BC-00BE, 00C0-00D6, 00D8-00F6, 00F8-00FF
0100-167F, 1681-180D, 180F-1FFF
200B-200D, 202A-202E, 203F-2040, 2054, 2060-206F
2070-218F, 2460-24FF, 2776-2793, 2C00-2DFF, 2E80-2FFF
3004-3007, 3021-302F, 3031-303F
3040-D7FF
F900-FD3D, FD40-FDCF, FDF0-FE44, FE47-FFFD
10000-1FFFD, 20000-2FFFD, 30000-3FFFD, 40000-4FFFD, 50000-5FFFD,
60000-6FFFD, 70000-7FFFD, 80000-8FFFD, 90000-9FFFD, A0000-AFFFD,
B0000-BFFFD, C0000-CFFFD, D0000-DFFFD, E0000-EFFFD
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.