dimanche 1 mars 2015

Partial class specialization for function pointer type and value

I'm using FLTK to do my GUI related stuff, and it requires functions of type void (*fn)( Fl_Widget*, void* ) to be registered as widget callbacks. I'm tired of creating function forwarders by hand that unpack the void*s into parameters and call appropriate static functions from my classes to do the work the user has requested.


I came up with a solution, but it requires a class to be specialized for both function type, and function address, and this is where I'm having problems. Here's some code:



template< typename T, typename fn_ptr_t, fn_ptr_t fn_ptr >
struct Fl_Callback_package;

template< typename T, typename Return, typename... Params >
struct Fl_Callback_package< T, Return (*)( Params... ), /* What goes here? */ >
{
//...
};


EDIT: To clarify - I don't want a specific function in place of /* What goes here? */, but rather I would like this parameter to be Return (*fn_ptr)( Params... ). When I try



template< typename T, typename Return, typename... Params >
struct Fl_Callback_package< T, Return (*)( Params... ), Return (*fn_ptr)( Params... ) >


I get an error from GCC 4.8.1 saying that fn_ptrwas not declared in this scope.


Aucun commentaire:

Enregistrer un commentaire