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

ID : 10094

viewed : 32

Tags : c++expressionemoticonsdigraphsc++

Top 5 Answer for c++ - What is this smiley-with-beard expression: "<:]{%>"?

vote vote

93

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.

vote vote

87

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

vote vote

80

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

66

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 
vote vote

60

Get Drawable from vector resource irrespective of, whether its vector or not:

AppCompatResources.getDrawable(context, R.drawable.icon); 

Note:
ContextCompat.getDrawable(context, R.drawable.icon); will produce android.content.res.Resources$NotFoundException for vector resource.

Top 3 video Explaining c++ - What is this smiley-with-beard expression: "<:]{%>"?

Related QUESTION?