Monday, 9 September 2013

Clean implementation of function template taking function pointer

Clean implementation of function template taking function pointer

I've managed to implement and test my function wrapper implementation,
however, the interface isn't as nice as it should be:
template < typename F, F* f >
void register_function( const char* name )
{
int (*lf) (lua_State *) = function_wrapper< F, f >;
register_native_function( lf, name );
}
While this works as expected, the usage requires to explicit template
parameters:
register_function< decltype(hello), &hello >( "hello" );
Obviously the first parameter could be deduced from the first one, so
ideally I'd like to just have
register_function< &hello >( "hello" );
Is it possible? Is there a neater way to do it?

No comments:

Post a Comment