简体   繁体   English

C ++ 17是否允许非ascii字符作为标识符?

[英]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: 我的问题是:

  1. Is this conforming to C++17? 这符合C ++ 17吗?
  2. Note that user-defined 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.

相关问题 C ++中的非ASCII字符串字符索引 - Non-ASCII String Character Index in C++ 如何在c ++字符串中搜索非ASCII字符? - How to search a non-ASCII character in a c++ string? C++17 中的“如果 constexpr”在非模板 function 中不起作用 - "If constexpr" in C++17 does not work in a non-templated function 为什么C ++ 17的std :: any不允许any_cast返回一个可移动的值? - Why does C++17's std::any not allow returning a movable value by any_cast? 在C ++中处理非Ascii Chars - Handling Non-Ascii Chars in C++ C ++:String to Character Array转换(删除非Ascii字符) - C++ : String to Character Array conversion (non-Ascii characters removed) 使用 repl.it 在 C++ 中将非 ASCII 字符输出到控制台 - Output non-ASCII character to the console in C++ using repl.it C ++电话号码字母拨号程序-语法错字? 还是非ASCII字符? - C++ Phone Number Letter Dialing Program - Syntax Typo? Or Non-ASCII character? C++17 是否提供生成器或其他内置方式来并行转换非实例化序列? - Does C++17 offer generators or another built-in way to transform a non-instantiated sequence in parallel? 对于 C++17 中的非标准布局类,“offsetof”“有条件地支持”是什么意思? - What does it mean for `offsetof` to be “conditionally-supported” for non standard-layout classes in C++17?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM