Skip to content

Commit

Permalink
added ref<T>::reset() function
Browse files Browse the repository at this point in the history
  • Loading branch information
wjakob committed Oct 4, 2023
1 parent cc5ac7e commit 8bd58c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/api_extra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,11 @@ functions:

Overwrite this reference with a pointer to another object

.. cpp:function:: void reset()

Clear the reference and reduces the reference count of the object (if not
``nullptr``)

.. cpp:function:: bool operator==(const ref &r) const

Compare this reference with another reference (pointer equality)
Expand Down
6 changes: 6 additions & 0 deletions include/nanobind/intrusive/ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ template <typename T> class ref {
return *this;
}

/// Clear the currently stored reference
void reset() {
dec_ref(m_ptr);
m_ptr = nullptr;
}

/// Compare this reference with another reference
bool operator==(const ref &r) const { return m_ptr == r.m_ptr; }

Expand Down

0 comments on commit 8bd58c7

Please sign in to comment.