Re: [boost] Runtime Dynamic Dispatch (boost-dispatch)

Message: 11 Date: Thu, 19 Oct 2006 01:52:32 +0200 From: Janek Kozicki <janek_listy@wp.pl> Subject: Re: [boost] Runtime Dynamic Dispatch (boost-dispatch) To: boost@lists.boost.org Message-ID: <20061019015232.42b1ce98@absurd> Content-Type: text/plain; charset=US-ASCII Dean Michael Berris said: (by the date of Wed, 18 Oct 2006 22:24:09 +0800)
Hi Everyone,
I'm about to make a shameless plug about the runtime dispatch library I've been working on the past few months (mostly testing and using in a project), which I've uploaded to the vault: http://tinyurl.com/ycsq6n for everyone to check out and comment on.
can it be used for multimethods ?
Hi Michael, It looks like the rival for your library is not a switch statement or an if-else statement, but a hash_map. In your rationale, you should make clear what your library can do that the following construct cannot: template <typename T> struct dynamic_dispatcher { typedef hash_map< T, boost::function<void ()> > type; }; dynamic_dispatcher<int>::type dispatcher; dispatcher[0] = boost::bind(&myfun0); dispatcher[1] = boost::bind(&myfun1); int i; std::cin >> i; dispatcher[i]() From my reading, the only difference is that hash map's operator[] will not throw in the case where an element is not found. Best Regards, Matthew Herrmann Zomojo Pty Ltd

Hi Matthew! On 10/19/06, Matthew Herrmann <matthew.herrmann@zomojo.com> wrote:
Hi Michael,
Dean is fine. :-)
It looks like the rival for your library is not a switch statement or an if-else statement, but a hash_map. In your rationale, you should make clear what your library can do that the following construct cannot:
[snipped code] I think I should improve on the documentation. :-) It's in the TODO now. :D
From my reading, the only difference is that hash map's operator[] will not throw in the case where an element is not found.
There's that, and there's also the capability of doing index validation and index routing/manipulation using a state-ful public member variable for the validator and the router. An instance of the validator type (which can be provided as a template parameter) and the router type (which can be provided as a template parameter as well) can be left for the user to manipulate and use based on the situation. An example would be: struct my_routing_strategy { int operator() (int i) const { return i % 10; }; }; struct my_validation_strategy { bool operator() (int i) const { return i < 9 ? false : true ; }; }; void function(int value) { std::cout << value << std::endl; }; // ... dispatcher<void(int), int, my_validation_strategy, my_routing_strategy> d; // d.validator is accessible // d.router is accessible d[10] = &function; d[9] = &function; // will throw HTH -- Dean Michael C. Berris C++ Software Architect Orange and Bronze Software Labs, Ltd. Co. web: http://software.orangeandbronze.com/ email: dean@orangeandbronze.com mobile: +63 928 7291459 phone: +63 2 8943415 other: +1 408 4049532 blogs: http://mikhailberis.blogspot.com http://3w-agility.blogspot.com http://cplusplus-soup.blogspot.com
participants (2)
-
Dean Michael Berris
-
Matthew Herrmann