GNOME Bugzilla – Bug 763393
Support sigc::slot<R(Args...)> declaration
Last modified: 2016-03-18 11:01:33 UTC
std::function, new in C++11, uses function-pointer syntax for its declaration. For instance, std::function<void(int)> for a function returning void and taking an int parameter. So we can expect people to get used to this and expect it with libsigc++. I guess it should be possible to support this alongside the exisiting syntax, so we'd have both: sigc::slot<void, int> slot; and sigc::slot<void(int)> slot; And for signals, too.
This was easy to add for libsigc++-3.0: For slot: https://git.gnome.org/browse/libsigcplusplus/commit/?id=911398e6f70693833f515c44aec9899a092d9250 For signal: https://git.gnome.org/browse/libsigcplusplus/commit/?id=e399c4ebdb633d242e7086ceb2a548057cd5889b However, I would prefer to avoid the repetition. I wonder if we could use a "using" alias declaration for this.
Apparently not: template <class T_return, class... T_arg> using signal<T_return(T_arg...)> = signal<T_return, T_arg...>; leads to: ../sigc++/signal.h:1136:13: error: partial specialization of alias templates is not permitted using signal<T_return(T_arg...)> = signal<T_return, T_arg...>; ^~
Avoiding the repetition would be particularly useful to add this to libsigc++-2.0, so we could deprecated the old syntax.
I want to do a libsigc++-2.8.0 release in the next couple of days, for the next GNOME release. I also want to add this new syntax in libsigc++-2.0 and deprecate the old syntax, but it would not be wise to do that so soon before a stable release. So I've done it for libsigc++-2.9/10 instead: https://git.gnome.org/browse/libsigcplusplus/commit/?h=libsigc%2b%2b-2-10&id=5573e97dd39e0f0c3f2ba6a3d5e56f21895b8796 and https://git.gnome.org/browse/libsigcplusplus/commit/?h=libsigc%2b%2b-2-10&id=a625175a289339da59fee39c7b22e20432f152b7
Created attachment 323766 [details] [review] 0001-slot-Add-deprecation-ifdefs-around-the-older-slot-Re.patch
Created attachment 323767 [details] [review] 0002-signal-Put-deprecation-ifdefs-aronud-the-older-slot-.patch These patches add deprecation #ifndefs. However, we use the deprecated slots and signals in the glibmm and gtkmm APIs so that would be very disruptive unless we can find some way to make that easier. Unfortunately, the ifndefs are a good way to encourage people to move to undeprecated API.
Isn't it possible to copy the slot<R(Args...)> and signal<R(Args...)> template specializations from libsigc++-3.0 to libsigc++-2.0? It would require less code repetition than the present solution in the libsigc++-2-10 branch. I've made a quick test by copying template<class T_functor, class T_return, class... T_arg> struct slot_call and template <class T_return, class... T_arg> class slot<T_return(T_arg...)> : public slot_base It seems to work, except for a slot<void()>, where there's some problem that involves adaptor_functor<> in adaptor_trait.h. Do you think this is worth further testing?
I had tried that, without success, though that wasn't the error that I had. But please do keep trying if you like.
Created attachment 324009 [details] [review] patch: Implement slot<R(Arg...)> with variadic template (libsigc++-2-10) This patch implements slot<R(Args...)> in the libsigc++-2-10 branch like it's implemented in the master branch, i.e. with a variadic template. The only difference is that I had to add a specialization of slot_call for functors without parameters. That's because other parts of libsigc++ 2 are not implemented with variadic templates, and the call return (typed_rep->functor_).template operator()<type_trait_take_t<T_arg>...> (a_...); is not accepted when sizeof...(T_arg) == 0. signal<R(Arg...)> can't be copied as easily from libsigc++ 3 to 2, because it contains a lot of C++14 stuff. I'll give it some more tries. I suppose we don't want to require C++14 in libsigc++ 2.
Great. Please go ahead and push that. Yes, we should not rush to use C++14 in libsigc++-2.0.
I've pushed the slot<R(Arg...)> patch. It's possible to implement also signal<R(Arg...)> with a variadic template in libsigc++-2.0, but I don't think it's worth doing. When I had copied struct signal_emit (including 2 specializations), class signal_with_accumulator and class signal<T_return(T_arg...)> from libsigc++-3.0, copied std::make_index_sequence from gcc's standard library, and replaced all decltype(auto), then signal.h had become longer, not shorter! And then I had not yet copied bound_mem_functor, which is required by make_slot().
(In reply to Kjell Ahlstedt from comment #11) > I've pushed the slot<R(Arg...)> patch. I don't see it.
Sorry, I see it now in the libsigc++-2-10 branch: https://git.gnome.org/browse/libsigcplusplus/log/?h=libsigc%2b%2b-2-10
Closing because this is all done now, I think.