Help answer threads with 0 replies.
Go Back > Blogs > Bits and Pixels
User Name


Concerning free software, programming, and whatever else I find interesting. Also the blog for my Web site,
Rate this Entry

C++ had lambda functions!

Posted 01-31-2013 at 01:21 AM by hydraMax

I'm doing a CS class which forces me to use C++. I was not very excited about this. However, I have recently be greatly encouraged by the discovery that C++ does, in fact, have lambda functions (or, more properly, anonymous functions) at least in the C++11 standard:

Basically, the big deal here is that I can construct new functions /inside/ of other functions, and even capture variables from the context. This, in turn, means that I can pass in customized or constructed functions into other functions, and thus program in a more functional programming style.

So, for example, instead of creating a function that reads lines and parses them, I can create a function that reads lines, and receives (as a parameter) a function that parses strings. This means that (1) I can keep the two functionality concepts distinct in the code (reading lines and parsing strings) and (2) the code can be easily re-factored, because I can replace the parsing function with another function that parses different, or I can reuse the parsing function as an argument to another function that retrieves strings in a different way.

I suppose I could do something similar with classes; but then I would have to muck around with setting up a sensible inheritance tree, and that does not appeal to me in the slightest.
Posted in Uncategorized
Views 1164 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 11:54 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration