Tho*_*ler 3 c++ reference logical-operators language-lawyer
考虑以下代码。对我来说,使用andandbitand显然违反了语义。
#include <iostream>
class C
{
public:
void f() and // meaning &&
{
std::cout << " f() and\n";
}
void f() bitand // meaning &
{
std::cout << " f() bitand\n";
}
};
int main()
{
C{}.f();
C c;
c.f();
}
Run Code Online (Sandbox Code Playgroud)
这是 C++ 规范中的疏忽还是编译器中的错误?
这是 C++ 规范中的疏忽还是编译器中的错误?
标准中的措辞表明两者都不是:
来自C++11 草案
2.6 替代标记 [lex.digraph]
- 为某些运算符和标点符号提供了替代标记表示。
- 在语言的所有方面,每个替代标记的行为分别与其主要标记相同,但拼写除外。
注意:在语言的各个方面。
当您查找替代运算符表示时,CppReference 有一些有关历史记录的信息:
[...] 源代码可以用 ISO 646 代码集之外的任何非 ASCII 7 位字符集编写
它指的是 ISO 646:1983,其中 1983 年是该标准的年份。因此,为没有特殊字符的系统和古代键盘引入了这些替代方案。