在进行std::shared_ptr大量工作时,我有点怀念shared_ref实现的过程。这是 的特化shared_ptr,它保证它永远不会包装 a nullptr(当然,给定正确的用法)。我有点想知道为什么它不在 C++11 标准中。执行过程中是否存在市长问题?我的头顶上什么也想不出来。
编辑:
我希望有一个类似于以下的界面:
template <typename T>
class shared_ref {
public:
shared_ref( T&& ref );
T& get();
T* operator&() const;
template< class Y >
void reset( Y&& obj );
long use_count() const;
bool unique() const;
void swap( shared_ref& r );
};
Run Code Online (Sandbox Code Playgroud)