简体   繁体   English

C ++ Boost函数比较

[英]C++ Boost function comparison

I have a class which contains boost::function as one of its arguments. 我有一个类,其中包含boost :: function作为其参数之一。 I have to make this class equality comparable but the boost::function is not equality comparable. 我必须使这个类平等可比,但boost :: function不是可比性的。 Is there a easy workaround for this problem? 这个问题有一个简单的解决方法吗?

Thanks, Gokul. 谢谢,Gokul。

boost::function is not eq_compare because there is good way to handle the fact that many functors are not eq_compare. boost :: function不是eq_compare,因为有很好的方法可以处理许多仿函数不是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 以下是对它的一些见解: 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, ie "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. 如果你真的真的需要这个eq_comparable东西,那么完全放弃boost :: function并滚动你自己。 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. 如果是这种情况,那么你应该看一下boost :: signals。

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

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