Proposal N4282 advocates a new type of non-owning smart pointer called an observer_ptr
. Its working name was exempt_ptr
and it's intended as a replacement for "raw pointers". But I don't understand its purpose, especially with this hypothetical code for what it's designed to achieve:
struct do_nothing
{
template <class T>
void operator ()(T*) { }; // do nothing
};
template <class T>
using non_owning_ptr = unique_ptr<T, do_nothing>;
Even after reading the article, I don't understand the purpose of a smart pointer that doesn't do nothing. What advantage does it have over a non-owning shared_ptr
or raw pointer?