edit Possibly can\'t be done, see Clean implementation of function template taking function pointer although answer 1 there has a C macro work-around https://stacko
You cannot use decltype
with a type as the goal is to obtain the type of a variable. But in decltype(&D)
, D
is a type.
I would rather pass throught a template function:
template
class unique_gptr : public std::unique_ptr {
public: unique_gptr(T* t) : std::unique_ptr(t, F) { };
};
template
unique_gptr make_unique_gptr(T pointer, D deleter)
{
return unique_gptr(pointer);
}
auto ptr = make_unique(new int(2), ::free_int);