24 explicit ref<T>(
const std::shared_ptr<T> & p)
36 static ref<T> unsafeFromPtr(
const std::shared_ptr<T> & p)
41 template<std::derived_from<std::enable_shared_from_this<T>> T2>
42 explicit ref(T2 & r) : p(r.shared_from_this())
46 T* operator ->()
const
56 operator std::shared_ptr<T> ()
const
61 std::shared_ptr<T> get_ptr()
const
67 std::optional<ref<T2>> try_cast()
const
69 if (
auto d = std::dynamic_pointer_cast<T2>(p)) {
70 return ref<T2>::unsafeFromPtr(d);
77 std::shared_ptr<T2> try_cast_shared()
const
79 return std::dynamic_pointer_cast<T2>(p);
83 operator ref<T2> ()
const
85 return ref<T2>::unsafeFromPtr((std::shared_ptr<T2>) p);
88 ref<T> & operator=(ref<T>
const & rhs) =
default;
90 bool operator == (
const ref<T> & other)
const
95 bool operator != (
const ref<T> & other)
const
100 bool operator < (
const ref<T> & other)
const
107 template<
typename T2,
typename...
Args>
109 make_ref(
Args&&... args);