Skip to main content

Module shared_ptr

Module shared_ptr 

Source
Expand description

Smart pointer for Objective-C objects.

Corresponds to Foundation/NSSharedPtr.hpp.

§C++ Equivalent

namespace NS {
template <class _Class>
class SharedPtr {
public:
    SharedPtr();
    ~SharedPtr();
    SharedPtr(std::nullptr_t) noexcept;
    SharedPtr(const SharedPtr<_Class>& other) noexcept;
    SharedPtr(SharedPtr<_Class>&& other) noexcept;
    SharedPtr& operator=(const SharedPtr<_Class>& other);
    SharedPtr& operator=(SharedPtr<_Class>&& other);
    _Class* get() const;
    _Class* operator->() const;
    explicit operator bool() const;
    void reset();
    void detach();
private:
    _Class* m_pObject;
};

template <class _Class>
SharedPtr<_Class> RetainPtr(_Class* pObject);

template <class _Class>
SharedPtr<_Class> TransferPtr(_Class* pObject);
}

Structs§

SharedPtr
A smart pointer that automatically manages the reference count of an Objective-C object.

Functions§

retain_ptr
Create a SharedPtr by retaining an existing raw pointer.
transfer_ptr
Create a SharedPtr by transferring ownership of an existing raw pointer.