libsigc++ Tips and Tricks

Lambda grouping

To set a widget’s sensitivity based on the results of two boolean functions:

sigc::connection cnx = my_signal.connect(
       sigc::group(sigc::mem_fun(widget, &Gtk::Widget::set_sensitive),
                   sigc::_1 && sigc::_2),
       sigc::mem_fun(this, &MyClass::GetBool1),
       sigc::mem_fun(this, &MyClass::GetBool2));

The sigc::group is like sigc::compose in that it calls a function and passes something to it. However, what it passes is one or more expressions using sigc::_1, sigc::_2, etc. These represent the parameters passed to this functor when called.

To pass the results of functions to the functor, you must wrap the whole thing in sigc::compose. Then it’s just a matter of passing expressions to be used for sigc::_1, etc.

NOTE: Make sure that you call cnx.disconnect() during cleanup, as some versions of libsigc++ have a bug where connections are not auto-disconnected when using sigc::group.

1 thought on “libsigc++ Tips and Tricks

Leave a Reply to Jay Satiro Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s