
-----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.