I have asked this question for concrete types. The provided solution is sufficient for those, but when it comes to inheritance, it fails. Would there be a solution to that as well?
Lets have a inheritance of classes Foo and IFoo such that class Foo: public IFoo and a function void use_weak_ptr(std::weak_ptr<IFoo>).
Is it possible to ensure that this compiles:
auto shared = std::make_shared<Foo>();
use_weak_ptr(shared);
And this does not:
use_weak_ptr(std::make_shared<Foo>());
One of the possible solutions - overload
use_weak_ptrfor allstd::shared_ptr.https://godbolt.org/z/Tj1a134bd
The linked answer is not a good answer.
const std::shared_ptr<IFoo>&&- const is redundant.