After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 763393 - Support sigc::slot<R(Args...)> declaration
Support sigc::slot<R(Args...)> declaration
Status: RESOLVED FIXED
Product: libsigc++
Classification: Bindings
Component: general
2.6.x
Other Linux
: Normal normal
: ---
Assigned To: libsigc++ maintainer(s)
libsigc++ maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2016-03-09 19:18 UTC by Murray Cumming
Modified: 2016-03-18 11:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
0001-slot-Add-deprecation-ifdefs-around-the-older-slot-Re.patch (1.05 KB, patch)
2016-03-12 16:57 UTC, Murray Cumming
needs-work Details | Review
0002-signal-Put-deprecation-ifdefs-aronud-the-older-slot-.patch (1.97 KB, patch)
2016-03-12 16:59 UTC, Murray Cumming
needs-work Details | Review
patch: Implement slot<R(Arg...)> with variadic template (libsigc++-2-10) (9.13 KB, patch)
2016-03-15 15:44 UTC, Kjell Ahlstedt
committed Details | Review

Description Murray Cumming 2016-03-09 19:18:19 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.
Comment 1 Murray Cumming 2016-03-11 10:16:55 UTC
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.
Comment 2 Murray Cumming 2016-03-11 10:18:31 UTC
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...>;
            ^~
Comment 3 Murray Cumming 2016-03-11 10:20:32 UTC
Avoiding the repetition would be particularly useful to add this to libsigc++-2.0, so we could deprecated the old syntax.
Comment 4 Murray Cumming 2016-03-12 16:57:17 UTC
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
Comment 5 Murray Cumming 2016-03-12 16:57:44 UTC
Created attachment 323766 [details] [review]
0001-slot-Add-deprecation-ifdefs-around-the-older-slot-Re.patch
Comment 6 Murray Cumming 2016-03-12 16:59:49 UTC
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.
Comment 7 Kjell Ahlstedt 2016-03-14 10:01:47 UTC
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?
Comment 8 Murray Cumming 2016-03-14 10:21:42 UTC
I had tried that, without success, though that wasn't the error that I had. But please do keep trying if you like.
Comment 9 Kjell Ahlstedt 2016-03-15 15:44:29 UTC
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.
Comment 10 Murray Cumming 2016-03-15 19:34:58 UTC
Great. Please go ahead and push that.

Yes, we should not rush to use C++14 in libsigc++-2.0.
Comment 11 Kjell Ahlstedt 2016-03-16 09:59:29 UTC
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().
Comment 12 Murray Cumming 2016-03-16 10:41:08 UTC
(In reply to Kjell Ahlstedt from comment #11)
> I've pushed the slot<R(Arg...)> patch.

I don't see it.
Comment 13 Murray Cumming 2016-03-16 11:22:35 UTC
Sorry, I see it now in the libsigc++-2-10 branch:
https://git.gnome.org/browse/libsigcplusplus/log/?h=libsigc%2b%2b-2-10
Comment 14 Murray Cumming 2016-03-18 11:01:33 UTC
Closing because this is all done now, I think.