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

发布于 2024-12-14 05:23:47 字数 277 浏览 4 评论 0原文

我试图理解这些不同绑定方法之间的区别。 boost::bind 和 boost:: 有一个类似的问题phoenix::bind

但是,如果有人可以用示例解释这一点,那就太好了。 boost::phoenix 是否是 boost::bind、booost::lambda 库的超集?

I am trying to understand the difference between these different bind approaches. There is a similar question at boost::bind and 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伤感在游骋 2024-12-21 05:23:47

我认为这个故事是(虽然我还不够老,无法讲述整个​​故事),boost::bind 最初是为了取代 C++98 中难以使用的 bind1st/bind2nd 而创建的,它实现了它的目标,现在是 C++11 的一部分。
但正如过去 10 年见证了 C++ 中函数式编程风格的兴起一样,boost::lambda 将其推向了如此远的高度(在它创建时),它支持 C++ 中使用纯库方法的相当广泛的函数构造。

然后据我从新闻组了解到,boost::lambda 和 boost::phoenix 的作者尝试将这两个库结合起来,因为它们处理几乎相同的问题。我猜这就是设计精美的 boost::phoenix2

然后是 boost::proto,它是一个用于编写表达式模板的库,或者我会说它是一个元库。于是phoenix再次涅槃,在boost::proto上重生,然后我们看到了phoenix3。我认为phoenix3是其中最强大的。

另一方面,C++11 添加了对 lambda 表达式的语言支持,我个人认为这非常有用且方便。唯一的缺点是它不是多态的(而 phoenix3 允许创建多态函数对象)。

作为我个人经验得出的结论,C++11 lambda 表达式是日常工作的选择(如果有的话)。它方便、清晰且编译时友好。 Phoenix3是多态的,非常强大,非常酷,缺点是编译时间长。

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.
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++.

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. I guess that was the beautifully designed 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. So the phoenix nirvana again, reborn itself on boost::proto, then we see phoenix3. I think phoenix3 is the most powerful among all above.

On the other hand, C++11 adds language support for lambda expression, which I personally find very useful and handy. The only drawback is it's not polymorphic (while phoenix3 allows creating polymorphic function objects).

As a conclusion that I come with personal experience, C++11 lambda expression is the choice for daily job, if available. It's handy, clear and compile-time friendly. Phoenix3 is polymophic, very powerful, very cool, with the drawback of long compile-time.

行至春深 2024-12-21 05:23:47

但是,如果有人可以用示例解释这一点,那就太好了。

举例说明什么?它们是同一概念的不同实现。

实际上重要的是:

  1. 自从 Boost.Phoenix 作为独立库发布(当然还有 boost::lambda::bind )以来,Boost.Lambda 已被正式弃用。
  2. boost::bind 的实现将来将会被 boost::phoenix::bind 的实现取代。它尚未被替换的唯一原因是 boost::bind 支持/具有针对较旧(读取:损坏)编译器(例如 MSVC6)的解决方法,而 Boost.Phoenix 严格要求 C++03-兼容的编译器。

结合这两个事实,很明显,在新代码中使用的唯一真正候选者是 boost::phoenix::bind

boost::phoenix 是否是 boost::bind、booost::lambda 库的超集?

是的,这是正确的。

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).
  2. The implementation of boost::bind is going to be replaced with that of boost::phoenix::bind in the future. The only reason it hasn't been replaced already is that boost::bind supports/has workarounds for older (read: broken) compilers e.g. MSVC6, whereas Boost.Phoenix strictly requires a C++03-compliant compiler.

Combine these two facts and it becomes clear that the only real candidate for use in new code is boost::phoenix::bind.

Also is it true that boost::phoenix is a superset of boost::bind, booost::lambda libraries?

Yes, this is correct.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文