本文共 1670 字,大约阅读时间需要 5 分钟。
本文翻译自:
I came across the following program, which compiles without errors or even warnings: 我遇到了以下程序,它编译时没有错误甚至是警告:
int main(){ <:]{%>; // smile!}
What does the program do, and what is that smiley-expression? 程序做了什么,笑脸表达是什么?
参考:
That's an empty lambda using a digraph disguise. 这是一个使用有向图伪装的空lambda。 Normal lambdas don't have beards. 普通的lambda没有胡须。
The program uses to represent the following: 该程序使用来表示以下内容:
[] {};
This is a lambda expression that does nothing. 这是一个什么都不做的lambda表达式。 The corresponding symbols have these equivalents: 相应的符号具有以下等价物:
<: = [%> = }
Though they are generally unneeded today, digraphs are useful for when your keyboard lacks certain keys necessary to use C++'s basic source character set, namely the graphical ones. 虽然今天通常不需要它们,但是当键盘缺少使用C ++基本源字符集所必需的某些键时,有用图有用,即图形键。 The combination of the characters that make up a digraph are processed as a single token. 组成有向图的字符组合作为单个标记处理。 This in turn makes up for any insufficiently-equipped keyboards or other such hardware or software. 这反过来弥补了任何配备不充分的键盘或其他此类硬件或软件。
The program is using , which allow C++ programming with keyboards (or text encodings) that may not have the characters C++ typically uses. 该程序使用 ,它允许使用可能没有C ++通常使用的字符的键盘(或文本编码)进行C ++编程。
The code resolves to this: 代码解析为:
int main(){ []{}; // smile!}
int main(){ <:]{%>; // smile! }
It's basically a (Lambda expression is one of features) using (both digraphs and trigraphs works on C++): 它基本上是一个使用的 (Lambda表达式是特性之一)(有向图和三字符都适用于C ++):
[] {};
Using only digraphs: 仅使用有向图:
<:]<%}; <:]<%%>;[:>{%>; // like my cubic hat?[:><%};[:><%%>;
Mixing them with Trigraphs: 将它们与Trigraphs混合:
<:??)<%??>; // popeye??(:>{??>; // pirate
转载地址:http://qgcnb.baihongyu.com/