有没有办法停止一个boost ::信号从调用其槽,如果其中一个返回true? [英] Is there a way to stop a boost::signal from calling its slots if one of them returns true?

查看:197
本文介绍了有没有办法停止一个boost ::信号从调用其槽,如果其中一个返回true?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用boost库,我的问题是关于boost ::信号。

我有一个信号可能调用许多不同的插槽,但只有一个插槽将匹配调用所以我想让这个特定的槽返回true,调用将停止。

是否可能?

它是否有效?

你能建议我更好的方法来做它,如果它不高效?


I am using the boost library and my question is about boost::signals.
I have a signal that might call many different slots but only one slot will match the call so I want this particular slot to return true and that the calling will stop.
Is it possible?
Is it efficient?
Can you guys suggest me a better way to do it if it's not efficient?

推荐答案

经过一些研究,我发现在boost文档中他们写了返回值的插槽

他们建议使用不同的组合器如下:

After some research I've found that in boost documentation they write about Slots that return values.
They suggest to use a different combiner like this:

struct breakIfTrue
{
  template<typename InputIterator>
  bool operator()(InputIterator first, InputIterator last) const
  {
    if (first == last)
      return false;

    while (first != last) {
      if (*first)
        return true;
      ++first;
    }
  }
};

boost::signal<bool(), breakIfTrue> sig;

现在为什么要做错事呢?

Now why is that the wrong thing to do?

这篇关于有没有办法停止一个boost ::信号从调用其槽,如果其中一个返回true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆