4 ms·
Doesn't that break when std::free does not have the default C++ calling convention? I think `decltype(std::free)` would be easier to read anyway, but writing a
by gurkendoktor 7y ago
Doesn't that break when std::free does not have the default C++ calling convention? I think `decltype(std::free)` would be easier to read anyway, but writing a deleter class that calls std::free in its operator() has the advantage that it will not use any memory in the unique_ptr thanks to the empty base class optimization.
- SamReidHughes 7y agoI don't think that's possible, and in that case the std::function wouldn't work either.
- gurkendoktor 7y agoI was thinking about calling conventions because std::free can use extern "C", but the function pointer declaration in C++ code points to an extern "C++" function, and the standard says these are two distinctive types. Are they guaranteed to be compatible - since they're only linkage specifiers, not calling conventions? I'm not sure. std::function would still work in this case because pointers to C functions have a normal operator().
- SamReidHughes 7y agoOh, right, it would work. Anyway, it looks like compilers have a known bug and they’re supposed to treat the types as incompatible.