19:15 this is not the only thing. I would say another big thing is that std::sort is actually faster than qsort (which is a big deal), and this is thanks to compilers being able to inline comparison. UPD: Great talk!
There is a Bug in slide 37. If void operator(void* ptr) {d_(static_cast(p))} is done then with smartptr_te widgetPtr = smartptr_re(new widget(), [](auto p){ delete p; }) above "widgetPtr" will be called for d_(static_cast(p)) which is not correct. Real type erasure is deleter function with whatever param as such will be templated and stored internally at COMPILE time. No lazy cast while invoking the deleter. IMO. GCC have a test static_assert(__is_invocable::value, "deleter expression d(p) is well-formed"); _Yp is of type widget and not Void.
@@josephlunderville3195 Indeed that structure looks very much like the pimpl idiom, but the concept is different. In pimpl the idea is to hide implementation details but all implementations are the same (pointer is used to decouple the single class implementation from the various users), and type erasure is meant to support many implementations (sharing an interface) - even ones unknown to the original designer of the interface.
@@Roibarkan There are multiple use cases for pimpl. including switching the implementation (class type) at runtime which you can't do with C++. I tried to switch vtable pointers once, but while working, code review team got heart attacks. Pimpl just means redirecting function calls
Always love talks by Fedor Pikus.
Fedor! Good to see him still do presentations.
Wow thanks. Need to rewatch it because is a complex topic for me. I recognize the work behind the presentation.
19:15 this is not the only thing. I would say another big thing is that std::sort is actually faster than qsort (which is a big deal), and this is thanks to compilers being able to inline comparison.
UPD: Great talk!
But if the comparison is not simple int/float comparison it is not. But creates more code, lot more code
There is a Bug in slide 37. If
void operator(void* ptr) {d_(static_cast(p))} is done then with
smartptr_te widgetPtr = smartptr_re(new widget(), [](auto p){ delete p; })
above "widgetPtr" will be called for d_(static_cast(p)) which is not correct.
Real type erasure is deleter function with whatever param as such will be templated and stored internally at COMPILE time. No lazy cast while invoking the deleter. IMO.
GCC have a test
static_assert(__is_invocable::value, "deleter expression d(p) is well-formed");
_Yp is of type widget and not Void.
So Type Erasure is just passing function pointers?
std::function is really great but I wish it had proper allocator support 😢
Nice!
Thanks!
Type Eraser video with different title. Same video uploaded..
1:17:29 Eduardo Madrid on thecppzoo: ruclips.net/video/s082Qmd_nHs/видео.html
It's PIMPL!
@@josephlunderville3195 Indeed that structure looks very much like the pimpl idiom, but the concept is different. In pimpl the idea is to hide implementation details but all implementations are the same (pointer is used to decouple the single class implementation from the various users), and type erasure is meant to support many implementations (sharing an interface) - even ones unknown to the original designer of the interface.
@@Roibarkan There are multiple use cases for pimpl. including switching the implementation (class type) at runtime which you can't do with C++. I tried to switch vtable pointers once, but while working, code review team got heart attacks. Pimpl just means redirecting function calls