Re: [Tinytl-general] function
Brought to you by:
egladysh
|
From: E. G. <egl...@co...> - 2003-12-10 21:38:07
|
Hi Dave,
boost::function doesn't support member functions directly.
You might want to consider several solutions to this problem.
1.
You could change the function signature to include the object pointer
something like this:
FUNC::function<void (myListener*, event& ev)>
cb(&myListener::member_event_callback);
cb(&listener, event);
Not very nice, because of the need to change the signature.
2.
A much better solution is to use boost::bind or std::bind1st
FUNC::function<void (event& ev)> cb(
std::bind1st( std::mem_fun(&myListener::member_event_callback), &listener )
);
FUNC::function<void (event& ev)> cb(
boost::bind( (&myListener::member_event_callback, &listener, _1 )
);
boost::bind<> is a powerful generalization of std::bind1st/bind2nd/mem_fun
Hope it helps,
Eugene
----- Original Message -----
From: "David Leffingwell" <dle...@ya...>
To: <tin...@li...>
Sent: Wednesday, December 10, 2003 11:51 AM
Subject: [Tinytl-general] function
> Hello Eugene,
>
> I saw your article in CodeProject, and downloaded
> tinytl from SourceForge. I tried it out a bit and it
> looks nice, however, regarding the "function"
> object...
>
> it would be nice if you could use non-static member
> functions in addition to static member functions or
> global functions.
>
> For example:
>
> class myListener
> {
> public:
> static void static_event_callback( event& ev )
> {
> event_visitor v;
> VAR::apply_visitor(v, ev);
> }
>
> void member_event_callback( event& ev )
> {
> event_visitor v;
> VAR::apply_visitor(v, ev);
> }
> };
>
> void global_event_callback( event& ev )
> {
> event_visitor v;
> VAR::apply_visitor(v, ev);
> }
>
> main()
> {
>
> SIG::signal< void (event&) > sig;
>
> // This works
> // FUNC::function<void (event&)>
> cb(global_event_callback);
>
> // This works
> FUNC::function<void (event&)>
> cb(myListener::static_event_callback);
>
> // Something like this would be nice
> // myListener listener;
> // FUNC::function<void (event&)>
> cb(&listener,member_event_callback);
>
> //
> connection con = sig.connect( cb );
>
> // ...
> }
>
> I was under the impression that Boost could do this.
>
> Thanks,
> Dave
>
> __________________________________
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing.
> http://photos.yahoo.com/
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive? Does it
> help you create better code? SHARE THE LOVE, and help us help
> YOU! Click Here: http://sourceforge.net/donate/
> _______________________________________________
> Tinytl-general mailing list
> Tin...@li...
> https://lists.sourceforge.net/lists/listinfo/tinytl-general
|