
A lightweight C++ signals and slots implementation - hellofunk
https://github.com/pbhogan/Signals
======
static_noise
They use templates like Signal0<>, Signal1<T1>, Signal2<T1,T2>, etc. with
fixed argument length instead of a more uniform solution like variadic
templates.

The code in the library is pretty old and I suppose that an update with
regards to C++11/14/17 would make it much better in every regard.

~~~
john_fushi
Given that the comments talk about compatibility issues with DOS and some DSPs
I believe it is not the direction pbhogan wants to take.

~~~
static_noise
As long as you can use a recent compiler there shouldn't be problems. The
resulting assembler code should be the same.

~~~
userbinator
A C++11 compiler for DOS?

~~~
okasaki
[http://www.delorie.com/pub/djgpp/mini-
faq.txt](http://www.delorie.com/pub/djgpp/mini-faq.txt)

gcc 5.3 (& co) for DOS!

------
ksherlock
The original code and explanation:

[http://www.codeproject.com/Articles/7150/Member-Function-
Poi...](http://www.codeproject.com/Articles/7150/Member-Function-Pointers-and-
the-Fastest-Possible)

~~~
eco
The author of this has been a long time contributor to D and brought these
ideas (and many other things) to the language. He's probably the biggest
reason D's CTFE (compile time function evaluation) is as powerful as it is,
having done most of the implementation.

------
tcbawo
If you wanted to maintain C++03 compatibility, a dispatching macro might be
useful to select the appropriate Signal template arity:
[http://stackoverflow.com/questions/16683146/can-macros-be-
ov...](http://stackoverflow.com/questions/16683146/can-macros-be-overloaded-
by-number-of-arguments)

~~~
gpderetta
No need for a dispatching macro, the usual solution in c++03 was to have a
template with a fixed maximum arity like this:

template<class T1 = default_, class T2 = default ..., class T10 = default_>
struct Signal;

where default is a placeholder type, and then have it dispatch internally to
the correct Signal/N/ via template specialization.

The template specialization themselves were generated either via preprocessor
metaprogramming or by an external tool.

------
modulus1
Maybe someone can chime in on why the standard library's std::function can't
be implemented as efficiently as this library purportedly is.

~~~
fleitz
As with most things it boils down to scope...

'Class template std::function is a general-purpose polymorphic function
wrapper. Instances of std::function can store, copy, and invoke any Callable
target -- functions, lambda expressions, bind expressions, or other function
objects, as well as pointers to member functions and pointers to data
members.'

This clearly does more than the OPs code and therefore has more complexity.

------
netheril96
Can the signal cross threads as in Qt's implementation?

~~~
dazzawazza
this equally old and pre modern c++ implementation can:
[http://sigslot.sourceforge.net/](http://sigslot.sourceforge.net/)

------
mattiemass
I had a ~ 6 month stint using Qt, after coming from iOS/OSX development. I
found it to be a really cumbersome mechanism, particularly when concurrency
was involved. I feel like there is a lot of momentum around functional
reactive. Anyone know of a comparison between this and reactive approaches?

------
EGreg
What are signals/slots the best paradigm for?

~~~
lordnacho
Observer pattern. Say you have some event that occurs, and some objects that
want to know about it. You make a signal and connect some observers to it.
When you fire the signal the observers receive some parameters and do their
calculations.

~~~
ajuc
Why it's interesting alternative: regular observer pattern make observed code
depend (at compile time) on the observing code. Signals/slots remove this
dependency, and allow for external configuration of these.

It's a dependency injection mechanism when you think about it.

------
pjmlp
What does it do better than libsigc++?

~~~
eps
This has got to stop.

Someone posts a link to A and immediately there is a comment - "How is it
better than B? How is it different from C?" You know what, bud, if you know
about B and C, excellent. Why don't you take a look at A and do everyone a
favor and answer your own question. Otherwise it sound like a lazy-ass
highbrow dismissal - "Pfft, A? Why bother? There is B, for chrissake, that
even the last imbecile here is familiar with."

Please try and make a sliver of effort when commenting on other people's work.

~~~
pjmlp
Because my time is limited and I would like to know why I should spend time
evaluating it, instead of using a battle tested library that exists since late
90's and that follows modern C++.

If the OP only wants to learn how to do it, or to build its portfolio for a
possible job interview, it is fair enough and I don't need to bother with it.

If the author wants to do a kick-ass replacement of libsigc++, then it is
probably worth my expensive time to look into it.

~~~
shin_lao
Everyone's time is limited, whether it's useful to you (or not), only you can
say. You are basically implying that the time of other people is less valuable
than yours when you say "please tell me why I must look at it".

~~~
detaro
Read it as "In case you have already compared A to B, I'd like to know what
you observed", and suddenly there is way less to be upset about.

~~~
new_hackers
How is this better than 'How is this better than'?

:-) (joking, you are on the right track here, 100% agree)

