C++ Boost功能比较

发布于 2024-09-10 07:19:47 字数 121 浏览 1 评论 0原文

我有一个类,其中包含 boost::function 作为其参数之一。我必须使此类相等具有可比性,但 boost::function 不可具有相等可比性。有一个简单的解决方法可以解决这个问题吗?

谢谢, 戈库尔。

I have a class which contains boost::function as one of its arguments. I have to make this class equality comparable but the boost::function is not equality comparable. Is there a easy workaround for this problem?

Thanks,
Gokul.

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

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

发布评论

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

评论(1

ゝ杯具 2024-09-17 07:19:47

boost::function 不是 eq_compare,因为有一个很好的方法来处理许多函子不是 eq_compare 的事实。以下是对其的一些见解: http ://www.boost.org/doc/libs/1_35_0/doc/html/function/faq.html#id690470

不幸的是,boosties 决定不提供基于策略的方法来让我们选择另一种选择,即“仅使用 eq-comparable 函子或破坏”实现,让我们有点塞满了。对于这种情况可能有一些蹩脚的解决方法,但我建议要么:

  1. 完全放弃 boost::function 并推出你自己的,如果你真的、真的需要这个 eq_comparable 的东西。
    或者
  2. 看看您的问题是否可以通过完全不同的方式解决。例如,许多人使用 function<>实现一种事件系统。如果是这种情况,那么您应该看看 boost::signals。

boost::function is not eq_compare because there is good way to handle the fact that many functors are not eq_compare. Here is a bit of insight into it: http://www.boost.org/doc/libs/1_35_0/doc/html/function/faq.html#id690470

Unfortunately, the boosties decided not to provide a policy-based approach which would allow us to select the alternative, i.e. "eq-comparable functors only or bust" implementation, leaving us a bit stuffed here. There might be a couple of crappy workarounds for this situation but I'd suggest to either:

  1. ditch boost::function altogether and roll your own if you really,really need this eq_comparable thing.
    or
  2. See if your problem can be solved in a very different way. For example many people use function<> to implement a kind of event system. If that's the case, then you should have a look at boost::signals.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文