Re: [sigc] Interesting minor libsigc++ 2 problems



Murray Cumming wrote:

These are not big problems, but they are interesting when porting to
libsigc++ 2:

1. In libsigc++ 1.2 you can do  button.signal_clicked().connect(*this,
&Gtk::Widget::hide)
but in libsigc++ 2 you need to write a separate intermediate method to
handle the signal and then call hide().
I came across this problem and found that using an static_cast to cast the "this" pointer to Gtk::Widget pointer works, but it really shouldn't be necessary.

button.signal_clicked().connect(sigc::mem_fun(static_cast<Gtk::Widget*>(this), &Gtk::Widget::hide));


2. In libsigc++ 1.2 you can override a method like so:
 void do_something(const Slot0<void>& slot);
 void do_something(const Slot1<void, int>& slot);
but in libsigc++ 2 that is ambiguous when you try to call
do_something().

Sorry for not giving actual compiler errors - I'm rushed.
This is a problem. I haven't written any overloaded functions that take a sigc::slot argument and so I never picked up on this before. This seems to be the problem. The sigc::slot<void> argument resolves to:

sigc::slot<void, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>

and the sigc::slot<void, int> argument resolves to

sigc::slot<void, int, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>

and the compiler sees these as ambiguous.

The only way around this ambiguity is to write code like this, for example for a class Window:

void do_something(const sigc::bound_mem_functor0<void, Window>& slot);

void do_something(const sigc::bound_mem_functor1<void, Window, int>& slot);

which is very unsitely, or use some typedefs

typedef  sigc::bound_mem_functor0<void, Window> SomeSlot;
void do_something(const SomeSlot& slot);

typedef  sigc::bound_mem_functor1<void, Window, int> SomeOtherSlot;
void do_something(const int> SomeOtherSlot& slot);

Is this really necessary? Could we have some intermedate sigc::slot0 and sigc::slot1 classes or does libsigc2 recommend the use of bound_mem_functorN<> directly.

Jeff Franks.










[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]