19 #ifndef LIB_CS_UNIQUE_POINTER_H
20 #define LIB_CS_UNIQUE_POINTER_H
27 template <
typename T,
typename Deleter = std::default_delete<T>>
31 using pointer =
typename std::unique_ptr<T, Deleter>::pointer;
32 using element_type =
typename std::unique_ptr<T, Deleter>::element_type;
33 using deleter_type =
typename std::unique_ptr<T, Deleter>::deleter_type;
49 : m_ptr(p, std::move(d))
75 return m_ptr ==
nullptr;
78 explicit operator bool() const noexcept {
82 operator std::unique_ptr<T, Deleter>() &&
noexcept
84 return std::move(m_ptr);
96 return m_ptr.get_deleter();
100 return m_ptr.get_deleter();
104 return m_ptr ==
nullptr;
108 return m_ptr.release();
112 if (m_ptr.get() == other) {
120 std::swap(m_ptr, other.m_ptr);
124 return m_ptr.release();
127 template <
typename U,
typename Deleter_U>
129 return this->m_ptr <=> ptr.m_ptr;
132 template <
typename U,
typename Deleter_U>
133 bool operator==(
const CsUniquePointer<U, Deleter_U> &ptr)
const noexcept {
134 return this->m_ptr == ptr.m_ptr;
137 template <
typename U>
138 auto operator<=>(
const U *ptr)
const noexcept {
139 return this->
get() <=> ptr;
142 template <
typename U>
143 bool operator==(
const U *ptr)
const noexcept {
144 return this->
get() == ptr;
147 auto operator<=>(std::nullptr_t)
const noexcept {
148 return this->m_ptr <=>
nullptr;
151 bool operator==(std::nullptr_t)
const noexcept {
152 return this->m_ptr ==
nullptr;
156 std::unique_ptr<T, Deleter> m_ptr;
158 template <
typename U,
typename D>
159 friend class CsUniqueArrayPointer;
162 template <
typename T,
typename... Args,
typename =
typename std::enable_if_t<! std::is_array_v<T>>>
165 return std::make_unique<T>(std::forward<Args>(args)...);
168 template <
typename T,
typename Deleter>
CsUniquePointer< T > make_unique(Args &&...args)
Definition: cs_unique_pointer.h:163
void swap(CsUniquePointer &other) noexcept
Definition: cs_unique_pointer.h:119
bool operator==(const CsUniquePointer< T1, Deleter1 > &ptr1, const CsUniquePointer< T2, Deleter2 > &ptr2)
Deleter & get_deleter() noexcept
Definition: cs_unique_pointer.h:95
Pointer data() const noexcept
Definition: cs_unique_pointer.h:87
void reset(Pointer other=nullptr) noexcept
Definition: cs_unique_pointer.h:111
bool is_null() const noexcept
Definition: cs_unique_pointer.h:103
bool operator!() const noexcept
Definition: cs_unique_pointer.h:74
Pointer operator->() const noexcept
Definition: cs_unique_pointer.h:70
Pointer release() noexcept
Definition: cs_unique_pointer.h:107
ElementType & operator*() const noexcept (noexcept (*std::declval< Pointer >()))
Definition: cs_unique_pointer.h:66
CsUniquePointer & operator=(CsUniquePointer &&other) = default
Pointer take() noexcept
Definition: cs_unique_pointer.h:123
Contains a pointer to an object and takes exclusive ownership.
Definition: cs_shared_pointer.h:28
~CsUniquePointer() = default
CsUniquePointer(std::unique_ptr< T, Deleter > &&p) noexcept
Definition: cs_unique_pointer.h:53
CsUniquePointer(Pointer p, Deleter d) noexcept
Definition: cs_unique_pointer.h:48
CsUniquePointer(Pointer p=nullptr) noexcept
Definition: cs_unique_pointer.h:43
deleter_type DeleterType
Definition: cs_unique_pointer.h:37
const Deleter & get_deleter() const noexcept
Definition: cs_unique_pointer.h:99
element_type ElementType
Definition: cs_unique_pointer.h:36
pointer Pointer
Definition: cs_unique_pointer.h:35
Pointer get() const noexcept
Definition: cs_unique_pointer.h:91
typename std::unique_ptr< cs_add_missing_extent_t< T >, Deleter >::deleter_type deleter_type
Definition: cs_unique_pointer.h:33
typename std::unique_ptr< cs_add_missing_extent_t< T >, Deleter >::element_type element_type
Definition: cs_unique_pointer.h:32
typename std::unique_ptr< cs_add_missing_extent_t< T >, Deleter >::pointer pointer
Definition: cs_unique_pointer.h:31
Namespace for the CsPointer library.