Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2004-07-09 12:52:16


Thomas Immich <immich_at_[hidden]> writes:

> Hello,
>
> I have the following problem:
>
> I want to add signals to an emitting class in a generic fashion. To
> add a signal data member for every signal type, I inherit privately
> from a list of signal types. I therefore use the mpl::inherit
> template.
>
> class Emitter:
> private boost::mpl::inherit<
> boost::signal<void (const Emitter&, int, int)>, // emitted
> when size changes
> boost::signal<void (const Emitter&, const char*)> //
> emitted when name changes
> > {
> public:
>
> };
>
> Since I want some signals to be connected automatically, I need to
> iterate the list of signal types. Is it possible to get a mpl::list
> with all the types I used within mpl::inherit?

The way to do this is to start with the type sequence, and generate the
inheritance from that:

   typedef mpl::vector<
      void(Emitter const&, int,int), void(Emitter const&, char const*)
> signals;

   class Emitter
     : private mpl::fold<
           signals
         , mpl::inherit<_1,_2>
         , mpl::empty_base
>
   {...};

HTH,
Dave

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net