|
Boost Users : |
Subject: Re: [Boost-users] [signals2] can a combiner return the slot iterator range?
From: Michael Powell (mwpowellhtx_at_[hidden])
Date: 2015-08-06 16:10:01
On Thu, Aug 6, 2015 at 4:01 PM, Nick Stokes
<randomaccessiterator_at_[hidden]> wrote:
> 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?
I'm not sure what you're shooting for.
When I'm approaching signals/slots or any sort of event driven system,
I generally treat that as a single event, with 2+ connections, events
being handled but each subscriber.
i.e. your first connection handles the double value; the second
connection would accept a double, and convert it to int to pass it
along to another int-based method
Along these lines.
> E.g.
>
> 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
> {
> public:
> void method1(int i) {..}
> void method2(double d) {..}
> };
>
>
> boost::signals2::signal< ComboSlot&() , MyRangeCombiner<ComboSlot> > sig;
>
> // in use
> for( ComboSlot& cs : sig() ) {
> cs.method1(3);
> cs.method2(3.14);
> }
>
>
> 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.
>
> Thanks
> Nick
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
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