What is this smiley-with-beard expression: "<:]{%>"?
Asked Answered
V

4

306

I came across the following program, which compiles without errors or even warnings:

int main(){
  <:]{%>; // smile!
}

Live example.

What does the program do, and what is that smiley-expression?

Venosity answered 1/4, 2013 at 0:54 Comment(5)
Would you please consider changing the accepted answer?Likewise
@Likewise He can't. Robot (the author of the accepted answer) said he will delete his answer. The whole point of giving him the tick is to prevent him from doing that since we don't want to lose valuable answers.Toting
@Mysticial: Fun answers are fun, but at the end of the day, it doesn't really help the readers.Likewise
@Likewise The answer is both fun, and describes what is going on. The fact it is an empty lambda, and has a digraph disguise, should be enough to provide readers with enough information. It doesn't hand-hold: the next answer down does. Hand holding is nice; but lack of same doesn't mean the OP should change their answer if they did not need it.Verbenaceous
Please don't edit the title like that. It's not "long", and it's used as an expression, which is an important point to the question (otherwise it might aswell have been used in a comment).Venosity
F
301

That's an empty lambda using a digraph disguise. Normal lambdas don't have beards.

Fore answered 1/4, 2013 at 0:56 Comment(0)
B
365

The program uses digraphs to represent the following:

[] {};

This is a lambda expression that does nothing. 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. 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.

Baccy answered 1/4, 2013 at 0:56 Comment(0)
F
301

That's an empty lambda using a digraph disguise. Normal lambdas don't have beards.

Fore answered 1/4, 2013 at 0:56 Comment(0)
R
70

The program is using digraphs, which allow C++ programming with keyboards (or text encodings) that may not have the characters C++ typically uses.

The code resolves to this:

int main(){
  []{}; // smile!
}
Recurvate answered 1/4, 2013 at 0:59 Comment(0)
P
62
int main(){
  <:]{%>; // smile!
}

It's basically a Lambda expression (Lambda expression is one of C++11 features) using digraphs (both digraphs and trigraphs works on C++):

[] {};

Using only digraphs:

<:]<%}; 

<:]<%%>;

[:>{%>; // like my cubic hat?

[:><%};

[:><%%>;

Mixing them with Trigraphs:

<:??)<%??>; // popeye

??(:>{??>; // pirate
Poesy answered 3/4, 2013 at 11:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.