Did Average's suggestion about variadic templates work?
I'd love to try variadic templates, unfortunetly VC++ doesn't support them yet. I decided to go with this solution:
template <typename T, T& F> void WrapperFunction () { /* stuff */ }
#define Wrap(X) WrapperFunction<decltype(X),X>()
Which works quite well. Most often I want to do this sort of thing its for optimization, but here I needed the function as a template parameter because I needed it embedded in the type.
I was working on a recursive decent parser, but I wanted everything short of the actual parsing to be done with metaprogramming (mostly as an excuse to learn some new tricks/techniques). Generally it works along the lines of:
auto digit = 0 | 1 | 2 | 3; // ect....
auto num = +digit;
auto if = i >> f;
auto then = t >> h >> e >> n;
auto else = e >> l >> s >> e;
auto end = e >> n >> d;
auto ifelse = if >> expr >> then >> exp >> !(else >> exp) >> end; // ! = 1 or none, expr defined elsewhere
auto p = SemanticAction(SomeFunc,ifelse);
// ect...
// parse
std::string str("stuff here to be parsed");
std::string::iterator i = str.begin();
Parse(p,i,str.end());
I needed to be able to add a semantic action, a function that would execute when a parser was recognized. The thing here was, it needed to be a template parameter because all the parsing info is embedded in the type.
All in all it was a fun exercise, much was learned, and its nice to have something usable at the end of it all ; )