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

-----Original Message----- From: boost-bounces@lists.boost.org
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];
Is it not possible at all to have a d(1,2,3) interface? With the tuples, you are specifying the interface already. It would be more natural.

Hi Sohail, On 10/20/06, Sohail Somani <s.somani@fincad.com> wrote:
Is it not possible at all to have a d(1,2,3) interface?
With the tuples, you are specifying the interface already.
I'm not sure what you mean by `d(1, 2, 3)'... If you have something like: void function(int a, int b, int c) { // do something with a, b, and c }; dispatcher<void(int, int, int)> d; d[0] = &function; d[0](1, 2, 3); Then definitely that's possible.
It would be more natural.
Can you elaborate on what you mean so that I don't misunderstand what you mean? -- 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