Something like
template<typename T, void (*func)(T*)>
struct Deleter{
void operator()(T* t) { func(t); }
};
??
Or if you want something a bit more robust
template <typename t>
struct function_traits;
template <typename R, typename A>
struct function_traits<R (*)(A)>
{
using t_ret = R;
using t_arg = A;
};
template <typename F, F* f>
struct Functor
{
using FT = function_traits<F*>;
typename FT::t_ret operator()(typename FT::t_arg a) {
return f(a);
}
};
void mydeleter(int*);
#define FUNCTOR(F) Functor<decltype(F),&F>
Or using the full might of C++11
template <typename F, F* f>
struct Functor
{
template<typename... A>
auto operator()(A&&... a) -> decltype(f(std::forward<A>(a)...)) {
return f(std::forward<A>(a)...);
}
};
#define FUNCTOR(F) Functor<decltype(F),&F>