[lambda] Return types in lambda expressions
I'm trying to use bind and lambda to create a functor that can receive an event generated by my GUI library, and dispatch an appropriate event into a boost::statechart::state_machine. The GUI library requires the functor to have the signature bool (const CEGUI::EventArgs&). An example of what works: template<typename EventType> bool GuiEvent(const CEGUI::EventArgs&, GameStateMachine& gsm) { gsm.process_event(EventType( )); return true; } //usage: GameStateMachine sm; ... boost::bind(&GuiEvent<EventExitGame>, _1, boost::ref(sm)); But is it possible to use lambda to eliminate the need for the function? It looks like I would use something along the lines of boost::bind<bool>(boost::ref(sm).process_event(EventExitGame( )) /*somehow return true here*/, _1); I'm just not quite seeing how I would get the lambda expression to return true there. Cheers.
"Michael Crawford"
I'm trying to use bind and lambda to create a functor that can receive an event generated by my GUI library, and dispatch an appropriate event into a
boost::statechart::state_machine. The GUI library requires the functor to have the signature bool (const CEGUI::EventArgs&). An example of what works: template<typename EventType> bool GuiEvent(const CEGUI::EventArgs&, GameStateMachine& gsm) { gsm.process_event(EventType( )); return true; }
//usage: GameStateMachine sm; ... boost::bind(&GuiEvent<EventExitGame>, _1, boost::ref(sm)); But is it possible to use lambda to eliminate the need for the function? It looks like I would use something along the lines of boost::bind<bool>(boost::ref(sm).process_event(EventExitGame( )) /*somehow return true here*/, _1);
As you don't provide the call signature of the callback registration method
(which should be there somewhere) this is probably not entirely correct, but
something like this should be possible (beware of typos):
void foo_add_callback(::boost::function0<bool> const& cb)
{ ... }
#include
participants (2)
-
Johan Nilsson
-
Michael Crawford