Boost logo

Boost :

Subject: Re: [boost] Interest in non-intrusive signal/slot lib?
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2015-05-16 19:19:32


On Sat, May 16, 2015 at 2:35 PM, Edward Diener <eldiener_at_[hidden]>
wrote:

> On 5/16/2015 3:04 PM, Emil Dotchevski wrote:
>
>> On Sat, May 16, 2015 at 11:50 AM, Edward Diener <eldiener_at_[hidden]>
>> wrote:
>>
>> I assume that the purpose of having the signal type be a pointer to a
>>>
>>>> function taking some data and returning an incomplete type instead of
>>>>> returning void is to make each signal type unique. But is this really
>>>>> necessary ?
>>>>>
>>>>>
>>>> It is necessary so that if you have:
>>>>
>>>> typedef struct button_down_(*button_down)(int x, int y);
>>>>
>>>> you can tell it apart from
>>>>
>>>> typedef struct button_up_(*button_up)(int x, int y);
>>>>
>>>>
>>>> I understand that the types are different but when would you ever use
>>> that
>>> knowledge in code ?
>>>
>>
>>
>> It seems you're asking why are different signals necessary, e.g. why would
>> I need to discriminate between a "button down" and a "button up" event --
>> which is puzzling. Anyway, the answer is that you need different signals
>> so
>> that you can tell connect<> which signal you're connecting (and emit<>
>> which signal you're emitting) from the specified emitter object:
>>
>> void handle_button_down( int x, int y );
>> void handle_button_up( int x, int y );
>>
>> auto c1=connect<button_down>(e,&handle_button_down);
>> auto c2=connect<button_up>(e,&handle_button_up);
>>
>
> typedef void (*button_down)(int x, int y);
> typedef void (*button_up)(int x, int y);
>
> void handle_button_down( int x, int y );
> void handle_button_up( int x, int y );
>
> auto c1=connect<button_down>(e,&handle_button_down);
> auto c2=connect<button_up>(e,&handle_button_up);
>
> Is there some reason why the above would not work ?

Yes, the reason is that in that case button_down and button_up are the same
type void(*)(int,int), so they'd be the same signal.

-- 
Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode

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