views:

373

answers:

2

On Page 175 Paragraph 1 of Effective C++ Meyers has this to say about generalized functors and binding:

I find what tr1::function lets you do so amazing, it makes me tingle all over. If you're not tingling , it may be because you're staring at the definition of ... and wondering what's going on with the ....

And I agree with him on bind and function. About lambda, Well I understand what lambda does and how it does it, but could someone post a book style mind-blowing snippet or a verbal outline of why lambda is supposed to (in Meyers' terminology) blow my socks off ? I ask because each area of C++ where the placeholder syntax is used seems like a hack to me (yes, I know enough about the functional method, so please no basics), I agree with the way it's used in bind and MPL; However, in the case of lambda I just want it justified so I can decide weather I should enter it into my repertoire.

-- edit --

This SO answer mentions the inlined creation of a functor using just placedholder syntax, he mentions advanced usage, and this is probably what I am after... in advanced usage is it still just inlined creation of functors ?

+4  A: 

Based on the comments left above, and the link in the question, the following is the answer I accept (community wiki) :

  1. Boost.Lambda fills the purpose of inline functor creation (that's the term I like). This functionality can be filled by Function + Bind, but it is more verbose than it needs to be, and for simple functors this is unnecessary — e.g., the sort shown in the comments above.

  2. There is obviously semantic overlap between the Function-Bind pair and Lambda — this is a historical artifact, and because Lambda has its raison d'être, it exists in Boost.

Hassan Syed
A: 

What is "cool" about it is that, as with boost foreach and boost parameter, injects/extends syntax into C++ which is not in the language, ie it emulates anonymous functions directly as parameters.

Viktor Sehr
Which should make one wonder, why use C++ in this case at all...
ima
Well, the alternative would be to write your own compiler with your own invented language.
Viktor Sehr
You're looking at this the wrong way ima, it's not why use C++ at all, it's why isn't this part of the C++ syntax yet. The C++0x lambda expressions are really cool, but they're only just a small step towards compiler-supported iterators and iterating over them.
Blindy