
as title! Thanks, Kevin -- Things don't just happen, you have to make them happen.

Kevin Wan wrote:
as title!
http://boost.org/more/submission_process.htm is linked from http://boost.org/ under Contribute/Submissions. HTH, m Send instant messages to your online friends http://au.messenger.yahoo.com

I've added a delegate implementation in C++. If anyone interested, please review it. the usage is like: #include <stdio.h> #include "delegate.h" void print_hello() { printf("print_hello\n"); } void print_world() { printf("print_world\n"); } class Object { public: Object() { printf("Object::Object\n"); } ~Object() { printf("Object::~Object\n"); } void print() const { printf("in Object::print\n"); } void test() const { wan::delegate<void()> d; d.add(this, &Object::print); d(); } }; class Functor { public: void operator()() const { printf("in Functor::operator() const\n"); } }; int main() { { wan::delegate<void()> d; d.add(&print_hello); d.add(&print_world); printf("\n"); d(); wan::delegate<void()> d1(d); printf("%u\n", sizeof(d)); d.add(d); d(); printf("\n"); d.remove(d1); d(); } { wan::delegate<void()> d; d.add(new Object(), &Object::print, true); d(); wan::delegate<void()> d1(d); wan::delegate<void()>* d2 = d.clone(); d1(); (*d2)(); delete d2; } { Object obj; obj.test(); } { wan::delegate<void()> d; d.add(new Functor(), true); d(); } } Thanks, Kevin On 2/10/06, Martin Wille <mw8329@yahoo.com.au> wrote:
Kevin Wan wrote:
as title!
http://boost.org/more/submission_process.htm is linked from http://boost.org/ under Contribute/Submissions.
HTH, m Send instant messages to your online friends http://au.messenger.yahoo.com _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Things don't just happen, you have to make them happen.

actually my implementation almost has the same behavior with C# delegate. the biggest advantage is easy to use. thanks, Kevin On 2/11/06, Sebastian Redl <sebastian.redl@getdesigned.at> wrote:
Kevin Wan wrote:
I've added a delegate implementation in C++.
What exactly are the advantages of your delegate over the existing libraries Boost.Function and Boost.Signals?
Sebastian Redl _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Things don't just happen, you have to make them happen.

in boost::signals docs, there is an example: deliverNews.connect <http://www.boost.org/doc/html/signalN.html#id2551390-bb>(boost::bind(&NewsMessageArea::displayNews, newsMessageArea, _1)); if use my implementation, it will look like: deliverNews.connect <http://www.boost.org/doc/html/signalN.html#id2551390-bb>(newsMessageArea, &NewsMessageArea::displayNews); as you see, it's kind of easier. and the implementation code is much simpler. i just want to share my library with others, if it helps. Thanks, Kevin On 2/11/06, Kevin Wan <wanjunfeng@gmail.com> wrote:
actually my implementation almost has the same behavior with C# delegate.
the biggest advantage is easy to use.
thanks, Kevin
On 2/11/06, Sebastian Redl <sebastian.redl@getdesigned.at> wrote:
Kevin Wan wrote:
I've added a delegate implementation in C++.
What exactly are the advantages of your delegate over the existing libraries Boost.Function and Boost.Signals?
Sebastian Redl _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Things don't just happen, you have to make them happen.
-- Things don't just happen, you have to make them happen.

Kevin Wan wrote:
i just want to share my library with others, if it helps.
This page shows the requirements and guidelines for Boost libraries: http://www.boost.org/more/lib_guide.htm This page shows the submission process: http://www.boost.org/more/submission_process.htm I suggest you upload the library to the vault and ask for comments then. Does your delegate support multicasting? If not, comparing it to Signals is not fair - you should compare it to Function instead. deliverNews = boost::bind(&NewsMessageArea::displayNews, newsMessageArea, _1); If it does, how is the implementation easier? It is not because it only supports member functions - Function takes care of that part of Signals. Sebastian Redl

my delegate supports: 1, functions 2, static member function 3, non-const member functions 4, const member functions 5, functors BTW, it supports multi-threading and i've uploaded the library to vault, the dir is /home/delegate thanks, Kevin On 2/11/06, Sebastian Redl <sebastian.redl@getdesigned.at> wrote:
Kevin Wan wrote:
i just want to share my library with others, if it helps.
This page shows the requirements and guidelines for Boost libraries: http://www.boost.org/more/lib_guide.htm
This page shows the submission process: http://www.boost.org/more/submission_process.htm
I suggest you upload the library to the vault and ask for comments then.
Does your delegate support multicasting? If not, comparing it to Signals is not fair - you should compare it to Function instead.
deliverNews = boost::bind(&NewsMessageArea::displayNews, newsMessageArea, _1);
If it does, how is the implementation easier? It is not because it only supports member functions - Function takes care of that part of Signals.
Sebastian Redl
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Things don't just happen, you have to make them happen.

Kevin Wan wrote: [lots of quoted text] Please don't overquote and don't put quotes at the bottom of your message. See http://boost.org/more/discussion_policy.htm#effective Regards, m Send instant messages to your online friends http://au.messenger.yahoo.com

sorry, i forgot to delete the quotes. and btw, i'd like to give a simple example of my delegate implementation. example.cc #include <stdio.h> #include "delegate.h" const char* bar = "##########################################"; void native_func(int value) { printf("%s\n", bar); printf("native function, value = %d\n", value); } class Object { public: static void static_member_func(int value) { printf("%s\n", bar); printf("static member function, value = %d\n", value); } void non_const_member_func(int value) { printf("%s\n", bar); printf("non-const member function, value = %d\n", value); } void const_member_func(int value) const { printf("%s\n", bar); printf("const member function, value = %d\n", value); } }; class Functor { public: void operator()(int value) { printf("%s\n", bar); printf("non-const functor, value = %d\n", value); } }; class ConstFunctor { public: void operator()(int value) const { printf("%s\n", bar); printf("const functor, value = %d\n", value); } }; int main() { typedef wan::delegate<void(int)> MyDelegate; Object obj; Functor functor; ConstFunctor constFunctor; MyDelegate dele; dele.add(&native_func); dele.add(&Object::static_member_func); dele.add(&obj, &Object::non_const_member_func); dele.add(&obj, &Object::const_member_func); dele.add(&functor); dele.add(&constFunctor); dele(111); printf("%s\n", bar); printf("\n\nafter remove operations\n\n"); dele.remove(&native_func); dele.remove(&obj, &Object::non_const_member_func); dele(222); printf("%s\n", bar); printf("\n\nadd delegate object to delegate object\n\n"); MyDelegate temp; temp.add(&native_func); temp.add(&obj, &Object::non_const_member_func); dele.add(&temp); dele(333); printf("%s\n", bar); } $ g++ example.cc -o test $ ./test ########################################## native function, value = 111 ########################################## static member function, value = 111 ########################################## non-const member function, value = 111 ########################################## const member function, value = 111 ########################################## non-const functor, value = 111 ########################################## const functor, value = 111 ########################################## after remove operations ########################################## static member function, value = 222 ########################################## const member function, value = 222 ########################################## non-const functor, value = 222 ########################################## const functor, value = 222 ########################################## add delegate object to delegate object ########################################## static member function, value = 333 ########################################## const member function, value = 333 ########################################## non-const functor, value = 333 ########################################## const functor, value = 333 ########################################## native function, value = 333 ########################################## non-const member function, value = 333 ########################################## $ thanks, Kevin On 2/11/06, Martin Wille <mw8329@yahoo.com.au> wrote:
Kevin Wan wrote:
[lots of quoted text]
Please don't overquote and don't put quotes at the bottom of your message. See http://boost.org/more/discussion_policy.htm#effective
Regards, m Send instant messages to your online friends http://au.messenger.yahoo.com _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Things don't just happen, you have to make them happen.
participants (3)
-
Kevin Wan
-
Martin Wille
-
Sebastian Redl