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

C++ExpressionEmoticonsDigraphs

C++ Problem Overview


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?

C++ Solutions


Solution 1 - C++

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.

Solution 2 - C++

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

Solution 3 - C++

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!
}

Solution 4 - C++

> 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionXeoView Question on Stackoverflow
Solution 1 - C++David GView Answer on Stackoverflow
Solution 2 - C++R. Martinho FernandesView Answer on Stackoverflow
Solution 3 - C++Drew DormannView Answer on Stackoverflow
Solution 4 - C++Khaled.KView Answer on Stackoverflow