Typo: in the user code example, I think the second should be in rather than out.
This is pretty cute - looks useful in practice. I think you can slightly enhance the probability of the compiler making the result efficient by using a switch statement, like:
This is pretty cute - looks useful in practice. I think you can slightly enhance the probability of the compiler making the result efficient by using a switch statement, like:
etc.In C++, you could do something fairly equivalent with lambdas, without having to involve the "evil" preprocessor.