【问题标题】:Reserved Names & User Literals保留名称和用户文字
【发布时间】:2020-06-03 18:03:35
【问题描述】:

C++ 标准在所有范围内保留以下划线后跟大写字母开头的名称。

这是否适用于用户文字运算符?

例如

int _MyInt; // reserved, violation

template < char... >
auto operator "" _MyInt ( ); // reserved???

【问题讨论】:

  • 就个人而言,我会保持安全并坚持小写。
  • 如果允许,看起来 C++ 实现应该避免在标准库中定义任何以下划线 + 大写字母开头的宏 (?)
  • @chi 他们总是可以#undef我想
  • @AsteroidsWithWings 正如对您发布的问题的答案的评论所说,_Foo 之类的情况不包括在内,这就是这个问题所要问的。

标签: c++ language-lawyer user-defined-literals


【解决方案1】:

不,它允许使用下划线后跟大写字母(否则为保留标识符)。

Source

我在支持上述内容的标准中只找到了一个例子,而不是正式的段落:

[over.literal]

double operator""_Bq(long double);    // OK: does not use the reserved identifier _­Bq
double operator"" _Bq(long double);   // uses the reserved identifier _­Bq 

因此,只要您不在 ""_Ud 之间添加空格,就可以 - 根据示例。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2015-02-01
  • 2015-08-31
  • 1970-01-01
  • 2010-12-26
  • 2016-07-05
  • 2015-06-13
  • 2012-02-24
  • 2021-09-05
相关资源
最近更新 更多