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

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Dean Michael Berris Sent: Thursday, October 19, 2006 2:09 AM To: boost@lists.boost.org Subject: Re: [boost] Runtime Dynamic Dispatch (boost-dispatch)
Hi Guys,
On 10/19/06, Sohail Somani <s.somani@fincad.com> wrote:
can it be used for multimethods ?
Doesn't seem like it. It uses a single value to dispatch so it's the same thing as single dispatch. Shouldn't be impossible to dispatch based on multiple values though.
I have an example use (in the accompanying tests) which uses a boost::tuple<> as the index type. If the aim was to use multiple values, you can create a tuple from it and use that as an index -- then couple it with a validation and routing strategy that allows you to validate and manipulate the index used for the dispatch.
If you need to call multiple methods, you can use the invoker interface to the dispatcher -- but still using single dispatch. You can even use Boost.Signals to register a set of methods and register it to the dispatcher on a single index.
Cool! Can it do Common Lisp-like dispatch where it calls one function if 0 <= x < 5 and another if 5 <= x < 10?

Hi Sohail! On 10/20/06, Sohail Somani <s.somani@fincad.com> wrote:
If you need to call multiple methods, you can use the invoker interface to the dispatcher -- but still using single dispatch. You can even use Boost.Signals to register a set of methods and register it to the dispatcher on a single index.
Cool! Can it do Common Lisp-like dispatch where it calls one function if 0 <= x < 5 and another if 5 <= x < 10?
Actually, yes! :D The following (incomplete) example below should be sufficient: struct function_chooser { int operator() (int i) const { if ((i >= 0) && (i < 5)) return 0; if ((i >= 5) && (i < 10)) return 5; return 11; }; }; typedef boost::dispatch::dispatcher<void(), int, boost::dispatch::always_true_validator<int>, function_chooser> dispatcher_t ; dispatcher_t d; d[0] = &function_1; d[5] = &function_2; d[11] = &default_function; int input; std::cin >> input; d[input]; 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
-
Sohail Somani