35 lifetime_watcher_{std::
move(lifetime_watcher)},
40 template<WatchableLifetime Lifetime>
49 template<std::derived_from<T> U>
51 lifetime_watcher_{
other.lifetime_watcher_},
61 lifetime_watcher_{std::move(
other.lifetime_watcher_)},
72 return lifetime_watcher_.
expired();
82 if (ptr_ ==
nullptr) {
85 assert_within_lifetime();
91 return not
expired() ? ptr_ :
nullptr;
96 assert_within_lifetime();
102 assert_within_lifetime();
108 return ptr_
and not lifetime_watcher_.
expired();
114 return {lifetime_watcher_,
dynamic_cast<U*
>(ptr_)};
117 void assert_within_lifetime()
const
119 if (lifetime_watcher_.
expired()) {
120 throw std::runtime_error{
"attempted to dereference a null pointer"};
127 template<
typename T1,
typename T2>
130 template<
typename T1>
137 template<
typename T,
typename U>
140 return lhs.ptr_ ==
rhs .ptr_;
146 return lhs.ptr_ ==
nullptr;
Definition lifetime_watcher.h:11
bool expired() const noexcept
Definition lifetime_watcher.h:15
Definition lifetimed_ptr.h:25
constexpr LifetimedPtr()=default
T * get() const
Definition lifetimed_ptr.h:80
T * get_if_not_expired() const
Definition lifetimed_ptr.h:89
LifetimedPtr(const LifetimedPtr< U > &other)
Definition lifetimed_ptr.h:50
constexpr LifetimedPtr(std::nullptr_t)
Definition lifetimed_ptr.h:31
T * operator->() const
Definition lifetimed_ptr.h:100
LifetimedPtr & operator=(LifetimedPtr &&) noexcept=default
LifetimedPtr< U > dynamic_downcast()
Definition lifetimed_ptr.h:112
bool expired() const noexcept
Definition lifetimed_ptr.h:70
T & operator*() const
Definition lifetimed_ptr.h:94
void reset()
Definition lifetimed_ptr.h:75
LifetimedPtr(LifetimedPtr &&) noexcept=default
LifetimedPtr(const LifetimedPtr &)=default
LifetimedPtr(const Lifetime &lifetime, T *ptr)
Definition lifetimed_ptr.h:41
LifetimedPtr & operator=(const LifetimedPtr &)=default
friend bool operator==(const LifetimedPtr< T1 > &, std::nullptr_t)
friend bool operator==(const LifetimedPtr< T1 > &, const LifetimedPtr< T2 > &)
LifetimedPtr(LifetimeWatcher lifetime_watcher, T *ptr)
Definition lifetimed_ptr.h:34
Definition custom_decoration_generator.h:5
bool operator==(const Class &, const Class &)
constexpr U to(T &&value)
Definition conversion.h:56
and
Definition algorithms.h:158