18#ifndef TRINITYCORE_UNIQUE_TRACKABLE_PTR_H
19#define TRINITYCORE_UNIQUE_TRACKABLE_PTR_H
26class unique_trackable_ptr;
32class unique_strong_ref_ptr;
51 template <
typename Deleter, std::enable_if_t<std::conjunction_v<std::is_move_constructible<Deleter>, std::is_invocable<Deleter&, T*&>>,
int> = 0>
53 :
_ptr(ptr,
std::move(deleter)) { }
58 :
_ptr(std::move(other._ptr)) { }
60 template <
typename T2, std::enable_if_t<std::is_convertible_v<T2*, T*>,
int> = 0>
68 _ptr = std::move(other._ptr);
72 template <
typename T2, std::enable_if_t<std::is_convertible_v<T2*, T*>,
int> = 0>
75 _ptr = std::move(other)._ptr;
100 return _ptr.operator->();
108 explicit operator bool()
const
110 return static_cast<bool>(
_ptr);
123 template <
class Deleter, std::enable_if_t<std::conjunction_v<std::is_move_constructible<Deleter>, std::is_invocable<Deleter&, T*&>>,
int> = 0>
126 _ptr.reset(ptr, std::move(deleter));
130 template <
typename T0>
133 template <
typename T0>
136 template <
typename T0,
typename... Args>
139 template <
typename T0>
142 template <
typename T0>
145 template <
typename T0>
148 template <
typename T0>
151 std::shared_ptr<element_type>
_ptr;
172 template <
typename T2, std::enable_if_t<std::is_convertible_v<T2*, T*>,
int> = 0>
174 :
_ptr(other._ptr) { }
178 template <
typename T2, std::enable_if_t<std::is_convertible_v<T2*, T*>,
int> = 0>
190 template <
typename T2, std::enable_if_t<std::is_convertible_v<T2*, T*>,
int> = 0>
193 _ptr = std::move(other)._ptr;
209 return _ptr.expired();
218 template <
typename T0>
221 template <
typename T0>
224 template <
class To,
class From>
227 template <
class To,
class From>
230 template <
class To,
class From>
233 template <
class To,
class From>
236 std::weak_ptr<element_type>
_ptr;
266 return _ptr.operator->();
274 explicit operator bool()
const
276 return static_cast<bool>(
_ptr);
287 template <
typename T0>
290 template <
class To,
class From>
293 template <
class To,
class From>
296 template <
class To,
class From>
299 template <
class To,
class From>
302 template <
class To,
class From>
305 template <
class To,
class From>
308 template <
class To,
class From>
311 template <
class To,
class From>
316 std::shared_ptr<element_type>
_ptr;
321template <
typename T1,
typename T2>
324 return left.
get() == right.
get();
327template <
typename T1,
typename T2>
330 return left.
get() <=> right.
get();
333template <
typename T1>
336 return left.
get() ==
nullptr;
339template <
typename T1>
342 return left.
get() <=>
nullptr;
345template <
typename T,
typename... Args>
349 ptr.
_ptr = std::make_shared<T>(std::forward<Args>(args)...);
357 ptr.
_ptr = std::make_shared<T>(N);
365 ptr.
_ptr = std::make_shared<T>(N, val);
373 ptr.
_ptr = std::make_shared<T>();
381 ptr.
_ptr = std::make_shared<T>(val);
387template <
class To,
class From>
391 to.
_ptr = std::static_pointer_cast<To>(other.
_ptr.lock());
395template <
class To,
class From>
399 to.
_ptr = std::const_pointer_cast<To>(other.
_ptr.lock());
403template <
class To,
class From>
407 to.
_ptr = std::reinterpret_pointer_cast<To>(other.
_ptr.lock());
411template <
class To,
class From>
415 to.
_ptr = std::dynamic_pointer_cast<To>(other.
_ptr.lock());
421template <
typename T1,
typename T2>
424 return left.
get() == right.
get();
427template <
typename T1,
typename T2>
430 return left.
get() <=> right.
get();
433template <
typename T1>
436 return left.
get() ==
nullptr;
439template <
typename T1>
442 return left.
get() <=>
nullptr;
445template <
class To,
class From>
451template <
class To,
class From>
457template <
class To,
class From>
463template <
class To,
class From>
469template <
class To,
class From>
475template <
class To,
class From>
481template <
class To,
class From>
487template <
class To,
class From>
Result of unique_weak_ptr::lock() function, this class holds a temporary strong reference to held obj...
pointer operator->() const
unique_strong_ref_ptr & operator=(unique_strong_ref_ptr &&)=delete
unique_strong_ref_ptr(std::shared_ptr< element_type > ptr)
std::shared_ptr< element_type > _ptr
~unique_strong_ref_ptr()=default
unique_strong_ref_ptr(unique_strong_ref_ptr const &)=delete
friend unique_strong_ref_ptr< To > dynamic_pointer_cast(unique_strong_ref_ptr< From > const &other)
friend unique_strong_ref_ptr< To > static_pointer_cast(unique_strong_ref_ptr< From > const &other)
unique_strong_ref_ptr & operator=(unique_strong_ref_ptr const &)=delete
friend unique_strong_ref_ptr< To > reinterpret_pointer_cast(unique_strong_ref_ptr< From > const &other)
unique_strong_ref_ptr(unique_strong_ref_ptr &&)=delete
friend unique_strong_ref_ptr< To > const_pointer_cast(unique_strong_ref_ptr< From > const &other)
element_type & operator*() const
Specialized variant of std::shared_ptr that enforces unique ownership and/or std::unique_ptr with std...
unique_trackable_ptr(unique_trackable_ptr const &)=delete
friend std::enable_if_t< std::is_bounded_array_v< T0 >, unique_trackable_ptr< T0 > > make_unique_trackable(std::remove_extent_t< T0 > const &val)
unique_trackable_ptr & operator=(unique_trackable_ptr const &)=delete
unique_trackable_ptr(unique_trackable_ptr< T2 > &&other) noexcept
std::shared_ptr< element_type > _ptr
void reset(pointer ptr, Deleter deleter)
friend std::enable_if_t< std::is_unbounded_array_v< T0 >, unique_trackable_ptr< T0 > > make_unique_trackable(std::size_t N, std::remove_extent_t< T0 > const &val)
~unique_trackable_ptr()=default
pointer operator->() const
friend std::enable_if_t<!std::is_array_v< T0 >, unique_trackable_ptr< T0 > > make_unique_trackable(Args &&... args)
unique_trackable_ptr & operator=(unique_trackable_ptr &&other) noexcept
unique_trackable_ptr(pointer ptr)
element_type & operator*() const
friend std::enable_if_t< std::is_bounded_array_v< T0 >, unique_trackable_ptr< T0 > > make_unique_trackable()
unique_trackable_ptr(pointer ptr, Deleter deleter)
unique_trackable_ptr & operator=(std::nullptr_t)
unique_trackable_ptr(unique_trackable_ptr &&other) noexcept
friend std::enable_if_t< std::is_unbounded_array_v< T0 >, unique_trackable_ptr< T0 > > make_unique_trackable(std::size_t N)
unique_trackable_ptr & operator=(unique_trackable_ptr< T2 > &&other) noexcept
void swap(unique_trackable_ptr &other) noexcept
Trinity::unique_trackable_ptr companion class, replicating what std::weak_ptr is to std::shared_ptr.
unique_weak_ptr & operator=(unique_weak_ptr &&other) noexcept=default
unique_weak_ptr()=default
unique_strong_ref_ptr< element_type > lock() const
unique_weak_ptr & operator=(unique_weak_ptr< T2 > &&other)
friend unique_weak_ptr< To > dynamic_pointer_cast(unique_weak_ptr< From > const &other)
unique_weak_ptr(unique_weak_ptr &&other) noexcept=default
std::weak_ptr< element_type > _ptr
unique_weak_ptr & operator=(unique_weak_ptr const &other)=default
friend unique_weak_ptr< To > static_pointer_cast(unique_weak_ptr< From > const &other)
unique_weak_ptr(unique_trackable_ptr< T > const &trackable)
unique_weak_ptr(unique_weak_ptr< T2 > &&other) noexcept
friend unique_weak_ptr< To > reinterpret_pointer_cast(unique_weak_ptr< From > const &other)
unique_weak_ptr & operator=(unique_trackable_ptr< T > const &trackable)
unique_weak_ptr(unique_weak_ptr const &other)=default
friend unique_weak_ptr< To > const_pointer_cast(unique_weak_ptr< From > const &other)
void swap(unique_weak_ptr &other) noexcept
~unique_weak_ptr()=default
unique_weak_ptr(unique_weak_ptr< T2 > const &other) noexcept
unique_weak_ptr< To > reinterpret_pointer_cast(unique_weak_ptr< From > const &other)
bool operator==(unique_trackable_ptr< T1 > const &left, unique_trackable_ptr< T2 > const &right)
unique_weak_ptr< To > const_pointer_cast(unique_weak_ptr< From > const &other)
std::enable_if_t<!std::is_array_v< T >, unique_trackable_ptr< T > > make_unique_trackable(Args &&... args)
unique_weak_ptr< To > static_pointer_cast(unique_weak_ptr< From > const &other)
unique_weak_ptr< To > dynamic_pointer_cast(unique_weak_ptr< From > const &other)
std::strong_ordering operator<=>(unique_trackable_ptr< T1 > const &left, unique_trackable_ptr< T2 > const &right)