Boost logo

Boost :

Subject: Re: [boost] [Signal] Variadic template implementation of signal/slot
From: Kevin Brandon (staticrealm_at_[hidden])
Date: 2009-05-21 13:01:22


On Wednesday 20 May 2009, Frank Mori Hess wrote:
>On Wednesday 20 May 2009, Kevin Brandon wrote:
>> Would anyone be interested in seeing my implementation of Signals/Slots
>> that uses the variadic template capability that will be a part of c++0x
>
>> standard?
>Sure. Can you give an outline of how you are using variadic templates and
>the interface changes?

I've submitted my template to the vault, under
  * Home / variadic_templates/Signal.hpp

I know that my implementation does not take advantage of the useful
templates boost provides like functional, variant, any, etc... So my
apologies for that; however, here is a summary of it ...

  Imagine...

  template<typename Result, typename ... Args>
  class Signal
  {
    Result operator ()(Args... args);
    template<class T>
    void connect(T* objPtr, Result (T::*memPtr)(Args...));
    void connect(Result (*funcPtr)(Args...));
    void disconnect();
    void disconnect(T* objPtr, Result (T::*memPtr)(Args...));
    void disconnect(Result (*funcPtr)(Args...));
  }

  Which does allow for this....

  Signal<float, int, int> signal;

  signal.connect(&foo_function_pointer);
  signal.connect(&foo, Bar::&bar_member_function_pointer);

  float foo = signal(1,2);

One neat feature that my implementation does allow for is that both
functions and function pointers are considered "slots" and all can connect
to the signal of the correct signature.

Its still infantile, but I thought that was going in a neat direction. There
is still quite a bit to do; however, I figured I'd find out it had enough
merit to share.

I did not make it threaded, thinking that I would leave that to the
functions themselves to thread or not. In that same spirit I did not
implement a block or unblock mechanism.
I did not create the += operator, of which I saw that it was vote down for
the boost Signal and Signal2 libraries.

As I mentioned before, if the interest exists, I will try to integrate and
respect the design decisions that already made in the other versions...

This is my first venture into sharing to the open source community, so my
apologies if it all seems a little wet behind the ears :P

Thanks for your time and audience,
  Kevin Brandon


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk