Thursday, September 10, 2015

What a line of code

I didn't know this line of code (in any language) will make sense but apparently it does:

auto l = [](){};

Look at all those brackets!

I encountered this when reading this blog ("http://blog.3d-logic.com/2014/12/08/c-async-development-not-only-for-for-c-developers-part-i-lambda-functions/").

It's a C++ lambda function and equivalent to this C# code:

Action l = () => {};

In C#, an Action type is a delegate (a function pointer) that returns null. The pair of empty parentheses means there is no parameter for this function. The empty curly braces means it's not doing any operation at all.

So in summary... it's a piece of code that accepts no parameter, doesn't do anything, and returns nothing. Effectively useless. But nevertheless valid code. And quite beautiful too.


No comments:

Post a Comment

What a line of code

I didn't know this line of code (in any language) will make sense but apparently it does: auto l = [](){}; Look at all those bracke...