开发者

boost::function and boost::bind are cool, but what is really cool about boost::lambda?

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 ?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜