The type of the deleter must be called with a type argument pointer. In your case pointerthere is D*. Your failure cannot be triggered with this, but a type argument is required instead pointer&, so your code was poorly formed without the need for diagnostics.
, decltype(mydel) -. Lambda , . , :
std::unique_ptr< D, decltype(mydel) > up( new D );
, . :
std::unique_ptr< D, decltype(mydel) > up( new D, mydel );
.
- -2013, , , . MSVC2013 ++ 11.
, , , lvalue D*. , .
, , ++ 17 :
template<auto* pfunc>
struct stateless {
template<class...Args>
decltype(auto) operator()(Args&&...args)const {
return std::invoke( pfunc, std::forward<Args>(args)... );
}
};
int main() {
class D{};
auto mydel = []( D*p ) { delete p; };
std::unique_ptr< D, stateless<+mydel> > up( new D );
return 0;
}
MSVC2015 (, , ).
++ 17 ++ 17, ( ++ 1z, , .)