xo-umbrella2/xo-refcnt/include/xo/refcnt/Unowned.hpp
Roland Conybeare dafaad4b1e git subrepo clone git@github.com:Rconybea/xo-refcnt.git xo-refcnt
subrepo:
  subdir:   "xo-refcnt"
  merged:   "bad785bd"
upstream:
  origin:   "git@github.com:Rconybea/xo-refcnt.git"
  branch:   "main"
  commit:   "bad785bd"
git-subrepo:
  version:  "0.4.9"
  origin:   "???"
  commit:   "???"
2026-06-06 22:18:44 -04:00

28 lines
828 B
C++

/* @file Unowned.hpp */
namespace xo {
namespace ref {
/* use this is a holder type for pointers that pybind11 should treat
* as "not-my-problem". in particular that pybind11 should never delete.
*/
template<typename T>
class unowned_ptr {
public:
unowned_ptr(T * x) : ptr_{x} {}
unowned_ptr(unowned_ptr const & x) = default;
~unowned_ptr() = default;
T * get() const { return ptr_; }
T * operator->() const { return ptr_; }
operator bool() const { return ptr_ != nullptr; }
unowned_ptr<T> & operator=(unowned_ptr<T> const & rhs) = default;
private:
T * ptr_ = nullptr;
}; /*unowned_ptr*/
} /*namespace ref*/
} /*namespace xo*/
/* end Unowned.hpp */