|
Boost Users : |
From: Johan Torp (johan.torp_at_[hidden])
Date: 2006-10-03 03:21:59
Monday, October 2, 2006, 10:05:23 PM, you wrote:
burlbo> Johan Torp wrote:
>> I often tend to have interfaces which take a boost::function<void()>
>> that is to be called when an event occurs. Quite often I need make two
>> separate function calls as response to one event. In these cases I
>> usually solve the problem using the following technique:
>>
>> void foo();
>> void bar();
>>
>> void call_two(const boost::function<void ()>& one, const
>> boost::function<void ()>& two)
>> { one(); two(); }
>>
>> boost::function<void ()> on_event = boost::bind(&call_two,
>> boost::bind(&foo), boost::bind(&bar));
burlbo> Why not just use Boost Signals to have a single signal just call your
burlbo> two different slots of foo and bar ? It seems you are unnecessarily
burlbo> trying to re-invent a wheel which has already been re-invented by the
burlbo> signals library.
Good point. Actually I have developed some classes which closely
resemble the signals library which I had already used extensively
when I found signals. Maybe I will switch to boost signals when some
shortcoming of my "library" becomes appearent, but for now it works
nicely and I prefer to not mix APIs.
In this particular case, boost::lambda solved the problem. I have a strong
functional programming background so doing things like this (higher
order programming) is much more natural to me than having to think about
concepts such as signals and slots.
-- Best regards, Johan Torp mailto:johan.torp_at_[hidden]
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