Я не знаю, как сделать это напрямую.Если вы хотите навсегда отключить все слоты, вы можете использовать метод disconnect_all_slots()
.Например:
boost::signal<int ()> foo;
...
foo.disconnect_all_slots();
Если вам нужно временно заблокировать их, лучший способ обойти это - использовать пользовательский объединитель, имитирующий это поведение.
#include <boost/signals.hpp>
#include <iostream>
//Define a reusable combiner that allows all slots to be blocked
template <typename Combiner>
struct blockable {
typedef typename Combiner::result_type result_type;
blockable() : blocked(false), combiner() {}
//Block or unblock all slots
void block() {blocked = true;}
void unblock() {blocked = false;}
template <typename InputIterator>
result_type operator()(InputIterator first, InputIterator last) {
//Either call into inner combiner, or throw if all slots are blocked
if (!blocked) return combiner(first, last);
throw std::runtime_error("All slots are blocked");
}
private:
bool blocked;
Combiner combiner;
};
//Quick and dirty sample using the blockable combiner
int bar() {
return 1;
}
int main() {
boost::signal<int (), blockable<boost::last_value<int> > > foo;
foo.connect(&bar);
try {
//show that it works
int x = foo();
std::cout << x << std::endl;
//Now block all slots
foo.combiner().block();
int y = foo();
//This won't run since the last call to foo() should throw
std::cout << y << std::endl;
} catch (std::exception& e) {
//Should get here via 2nd call to foo()
std::cout << e.what() << std::endl;
}
return 0;
}