The reference is a 1h YouTube video.
The reference is a 1h YouTube video.
Simple attempts to fix don't really work. Not even sure an ABI break will be enough, but it would at least be a minimum requirement.
But unique_ptr in public interfaces feels like code smell. I have done it, but not proudly.
struct iface
{
virtual ~iface(){ }
virtual void doSomething() = 0;
static std::unique_ptr<iface> create();
}
I don't know good ways to replace unique_ptr here.Requiring library users to #include the concrete implementation is not good: inflates compilation time, pollutes namespaces, pollutes IDE's autocompletion DB.
Can go C-style i.e. pass double pointer argument to the factory, or return raw pointer. But then user needs to remember to destroy the object.
But it would often be better to make a move-only value type, and return that instead.
I wrote up a reddit post for a possible workaround for removing the overhead. It's standard C++, no ABI break is required. It's not without caveats though: https://www.reddit.com/r/cpp/comments/do8l2p/working_around_...
Compilers have an attribute to remove this overhead, but it's an ABI break to do it.