Re: variadic templates - packing parameter packs?
On Nov 12, 5:40 pm, I wrote:
On Nov 11, 12:30 pm, alas.ric...@googlemail.com wrote:
The situation, modulo a little simplification:
The C++ functions to be called must have a prototype of the form:
void function_name(Stack& stack);
I'm supposed to pop one item of 'user data' (which I can set when I
register the callback) off the stack, followed by the incoming
parameters, and then push my final result onto it.
Naturally, I don't want to write all my externally callable functions
in that form, and was hoping variadic templates could help.
Below is a sketch of the code I had hoped to write, but I don't know
how to express the three lines marked with question marks. I was
wondering if it is possible... or even a reasonable thing to be
wanting to do? (Pardon errors in the rest of the code, please!).
....
What you have to do is to invert the flow so that you end up with the
call to do_call at the bottom of the recursion.
WARNING: the following code is untested!
And wrong, of course.
Add the following functions:
template<typename H, typename... Ts, typename... As>
static R apply_all(CallbackHandler<R, Ps...>* pHandler, Stack& stack,
As&... as) {
H h;
stack.pop(h);
return apply_all(pHandler, stack, as..., h);
Should be
return apply_all<Ts..., As..., H>(pHandler, stack, as..., h);
}
template<typename... As>
static R apply_all(CallbackHandler<R, Ps...>* pHandler, Stack& stack,
As&... as) {
return pHandler->do_call(as...);
}
And call them as follows:
static void external_call_slot(Stack& stack) {
CallbackHandler<R, Ps...>* pHandler;
R r = apply_all(pHandler, stack);
Should be
R r = apply_all<Ps...>(pHandler, stack);
stack.push(r);
}
Yechezkel Mett
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]