tsuki
tsuki

Reputation: 907

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.

Upvotes: 2

Views: 1224

Answers (1)

T.C.
T.C.

Reputation: 137301

You put Return (*fn_ptr)( Params... ) in the wrong place. It's a template parameter of the partial specialization, so it goes into the template <...>.

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

template< typename T, typename Return, typename... Params, Return (*fn_ptr)( Params... ) >
struct Fl_Callback_package< T, Return (*)( Params... ), fn_ptr >
{
  //...
};

Upvotes: 6

Related Questions