Ideally, I would also want static binding of int to pointer-to-member-function.
My first approach used several template helpers and virtual dispatch. It worked, but was much bigger than I'd like.
My second approach used one simple template helper, and a lookup array, and uses runtime binding. It works, and isn't too big, but doesn't help much, either.
I'm thinking that the solution to this problem really should be a switch() statement. Yes, I can build direct-dispatch object-oriented structures to solve this problem, but: why?
#define BEGIN_DISPATCH(code,data) { void *_ptr = data; switch(code) {#define DISPATCH(type,code) case code: On ## type(*(type *)_ptr); break;#define END_DISPATCH() default: UnknownPacket(); break; } }
No muss, no fuss. The drawback is that I have to hard-code the code for each type, which is already coded in another table (used to define the serialization), and putting the same piece of data in two places goes against my better judgement.