简体   繁体   English

boost :: bind,boost :: lambda :: bind和boost :: phoenix :: bind之间的区别

[英]Difference between boost::bind, boost::lambda::bind and boost::phoenix::bind

I am trying to understand the difference between these different bind approaches. 我试图理解这些不同绑定方法之间的区别。 There is a similar question at boost::bind and boost::phoenix::bind boost :: bind和boost :: phoenix :: bind也有类似的问题

But, if anyone can explain this with examples it would be great. 但是,如果有人能用例子解释这一点,那就太好了。 Also is it true that boost::phoenix is a superset of boost::bind, booost::lambda libraries? 也就是说,boost :: phoenix是boost :: bind,booost :: lambda库的超集吗?

I think the story is (though I'm not old enough to tell the whole story), boost::bind was first created to replace the hard-to-use bind1st/bind2nd in C++98, and it achieves its goal and now part of C++11. 我认为这个故事是(尽管我还不够讲述整个故事),首先创建了boost :: bind来替换C ++ 98中难以使用的bind1st / bind2nd,它实现了它的目标,现在是C ++ 11的一部分。 But also as last 10 years saw the rise of functional programming style in C++, boost::lambda pushes it so far (at the time it was created) that it supports a reasonably wide set of functional constructs with pure library approach in C++. 但是在过去的10年里,随着C ++中函数式编程风格的兴起,boost :: lambda推动它到目前为止(在它创建时),它支持C ++中使用纯库方法的相当广泛的函数结构集。

And then as I know from the news group, the author of boost::lambda and boost::phoenix try to combine the two libraries as they deal with virtually the same problem. 然后我从新闻组了解到,boost :: lambda和boost :: phoenix的作者尝试将两个库结合起来,因为它们处理的问题几乎相同。 I guess that was the beautifully designed boost::phoenix2 我猜那是设计精美的boost :: phoenix2

And then there comes boost::proto, which is a libary for writing expression templates, or I'd say it's a meta-library. 然后是boost :: proto,它是一个用于编写表达式模板的库,或者我说它是一个元库。 So the phoenix nirvana again, reborn itself on boost::proto, then we see phoenix3. 所以凤凰必杀技再次在boost :: proto上重生,然后我们看到了phoenix3。 I think phoenix3 is the most powerful among all above. 我认为phoenix3是上述最强大的。

On the other hand, C++11 adds language support for lambda expression, which I personally find very useful and handy. 另一方面,C ++ 11增加了对lambda表达式的语言支持,我个人认为这非常有用且方便。 The only drawback is it's not polymorphic (while phoenix3 allows creating polymorphic function objects). 唯一的缺点是它不是多态的(而phoenix3允许创建多态函数对象)。

As a conclusion that I come with personal experience, C++11 lambda expression is the choice for daily job, if available. 作为我个人经验的结论,如果可以的话,C ++ 11 lambda表达式是日常工作的选择。 It's handy, clear and compile-time friendly. 它方便,清晰,编译时友好。 Phoenix3 is polymophic, very powerful, very cool, with the drawback of long compile-time. Phoenix3是多变的,非常强大,非常酷,具有编译时间长的缺点。

But, if anyone can explain this with examples it would be great. 但是,如果有人能用例子解释这一点,那就太好了。

Examples of what? 什么样的例子? They're different implementations of the same concept. 它们是同一概念的不同实现。

Here's what's actually important: 这是真正重要的:

  1. Boost.Lambda has been officially deprecated since Boost.Phoenix was released as a standalone library (and of course boost::lambda::bind along with that). Boost.Lambda自从Boost.Phoenix作为一个独立的库发布以来一直被正式弃用(当然还有boost::lambda::bind )。
  2. The implementation of boost::bind is going to be replaced with that of boost::phoenix::bind in the future. boost::bind的实现将来会被boost::phoenix::bind替换。 The only reason it hasn't been replaced already is that boost::bind supports/has workarounds for older (read: broken) compilers eg MSVC6, whereas Boost.Phoenix strictly requires a C++03-compliant compiler. 它尚未被替换的唯一原因是boost::bind支持/具有较旧(读取:已损坏)编译器(例如MSVC6)的变通方法,而Boost.Phoenix严格要求符合C ++ 03的编译器。

Combine these two facts and it becomes clear that the only real candidate for use in new code is boost::phoenix::bind . 结合这两个事实,很明显,在新代码中使用的唯一真正的候选者是boost::phoenix::bind

Also is it true that boost::phoenix is a superset of boost::bind, booost::lambda libraries? 也就是说,boost :: phoenix是boost :: bind,booost :: lambda库的超集吗?

Yes, this is correct. 是的,这是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM