Boost logo

Boost Users :

Subject: [Boost-users] [signals2] can a combiner return the slot iterator range?
From: Nick Stokes (randomaccessiterator_at_[hidden])
Date: 2015-08-06 16:01:44

I'd like a combiner to return the slot iterator as a range.

1. What is the type of the iterator? (any exposed meta function to get
this? I couldn't see in the docs)
2. Are the itertors valid after the combiner returns?
3. Is this already possible without a custom combiner?


template<class T>
struct MyRangeCombiner
   typedef boost::iterator_range< some_meta<T>::type > result_type;

   template<class It>
    result_type operator()(It begin, It end) const {
           return boost::make_iterator_range(begin,end);

class ComboSlot
     void method1(int i) {..}
     void method2(double d) {..}

boost::signals2::signal< ComboSlot&() , MyRangeCombiner<ComboSlot> > sig;

// in use
for( ComboSlot& cs : sig() ) {

A broader picture is the following: More often than not I have a family
of events (signals). The slots are connected in groups, such as the the
ComboSlot above. One straightforward implementation is to maintain
different signals for every method:

ComboSlot cs;
boost::signals2::signal< void(int) > sigMethod1;
boost::signals2::signal< void(double) > sigMethod2;
sigMethod1.connect( &ComboSlot::method1, _1 );
sigMethod2.connect( &ComboSlot::method2, _1 );


There is quite a bit of waste associated with above. Not only it requires
more code, but also we know for sure that if method1 is connected, so will
method2, and they will be connected to slots who calls the corresponding
method on the same ComboSlot.

One other alternative is to write a combiner which loops and calls the
method within operator(). Returning a range would be a better alternative.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at