Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以在boost::signal. 它可能会得到一些布尔函数,当我发出信号时,它应该检查函数是否返回 true 然后发出。
boost::signal
我不想在发射期间检查条件,因为它在很多地方发射。我也不想检查插槽中的条件,因为它不应该知道该条件。
如果您需要以这种方式从许多地方发出信号,我会为它添加一个方法:
void emitSignal() { if( /* condition */ ) { _signal(); } }
然后你打电话emitSignal()而不是直接发出信号。
emitSignal()
我将其设计为适配器。这个适配器有一个用于原始信号的插槽,检查条件,如果测试通过,则发出第二个信号。