I have this snippet of code:
template<typename... Args> class function_helper<void(Args...)>{
public:
typedef void(*generic_function)(Args...);
static void call(lua_State* l, generic_function func, Args... args){
func(args...);
}
template<typename... retrieved> static void call(lua_State* l, generic_function func, retrieved... read){
call(l, func, read..., to<typename std::tuple_element<sizeof...(read), std::tuple<Args...> >::type >(l, 1+sizeof...(read)));
}
static int wrapper(lua_State* l){
assert(lua_isuserdata(l, lua_upvalueindex(1)));
call(l, generic_function(lua_touserdata(l, lua_upvalueindex(1))));
return 0;
}
};
The purpose is to have a free function wrapper (with arguments list of any length), so that it’s callable by lua by pushing function_helper::wrapper.
All works well. My “worry” is that g++ is not smart enough to understand that the recursive calls of call could be replaced with a single call of the like of
call(luastate, to<type1>(luastate, 1), to<type2>(luastate, 2), to<type3>(luastate, 3), ...);
My compiler is g++ 4.6.1. If you have info on g++ 4.7 or newer that would be welcome as well.
P.S.
the use of std::tuple is a workaround to a g++ 4.6 limitation, it cannot unpack directly a vararg template list to a vararg argument or something.
I asked in #gcc @ freenode. They said yes, unless you take the pointer of function local variables. But since there’s none, the answer should be yes.