51 if (m_ptr !=
nullptr) {
56 constexpr ~IntrusiveSharedPtr() {
57 if (m_ptr !=
nullptr) {
69 if (m_ptr !=
nullptr) {
80 requires(!std::same_as<T, U> && std::convertible_to<U*, T*>)
84 if (m_ptr !=
nullptr) {
97 if (m_ptr == rhs.m_ptr) {
101 if (m_ptr !=
nullptr) {
102 dec_ref_count(m_ptr);
107 if (m_ptr !=
nullptr) {
108 inc_ref_count(m_ptr);
120 template <
typename U>
121 requires(!std::same_as<T, U> && std::convertible_to<U*, T*>)
124 if (m_ptr == rhs.m_ptr) {
128 if (m_ptr !=
nullptr) {
129 dec_ref_count(m_ptr);
134 if (m_ptr !=
nullptr) {
135 inc_ref_count(m_ptr);
147 : m_ptr{std::exchange(rhs.m_ptr,
nullptr)} {}
154 template <
typename U>
155 requires(!std::same_as<T, U> && std::convertible_to<U*, T*>)
158 : m_ptr{std::exchange(rhs.m_ptr,
nullptr)} {}
168 if (m_ptr == rhs.m_ptr) {
172 std::swap(m_ptr, rhs.m_ptr);
183 template <
typename U>
184 requires(!std::same_as<T, U> && std::convertible_to<U*, T*>)
187 if (m_ptr == rhs.m_ptr) {
191 std::swap(m_ptr, rhs.m_ptr);
201 constexpr T*
get() const noexcept {
return m_ptr; }
208 constexpr T&
operator*() const noexcept {
return *m_ptr; }
222 explicit constexpr operator bool() const noexcept {
return m_ptr !=
nullptr; }
233 return lhs.m_ptr == rhs.m_ptr;
245 return lhs.m_ptr != rhs.m_ptr;
254 std::nullptr_t)
noexcept {
255 return lhs.m_ptr ==
nullptr;
265 return nullptr == rhs.m_ptr;
275 std::nullptr_t)
noexcept {
276 return lhs.m_ptr !=
nullptr;
287 return nullptr != rhs.m_ptr;
302template <
typename T,
typename... Args>
303IntrusiveSharedPtr<T> make_intrusive_shared(Args&&... args) {
304 return IntrusiveSharedPtr<T>{
new T(std::forward<Args>(args)...)};
318template <
typename T,
typename Alloc,
typename... Args>
319IntrusiveSharedPtr<T> allocate_intrusive_shared(Alloc alloc, Args&&... args) {
320 auto ptr = std::allocator_traits<Alloc>::allocate(alloc,
sizeof(T));
321 std::allocator_traits<Alloc>::construct(alloc, ptr,
322 std::forward<Args>(args)...);
323 return IntrusiveSharedPtr<T>{ptr};
Definition intrusive_shared_ptr.hpp:29
constexpr IntrusiveSharedPtr(IntrusiveSharedPtr< U > &&rhs) noexcept
Definition intrusive_shared_ptr.hpp:156
constexpr IntrusiveSharedPtr< T > & operator=(IntrusiveSharedPtr< T > &&rhs) noexcept
Definition intrusive_shared_ptr.hpp:166
friend constexpr bool operator==(std::nullptr_t, const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:263
constexpr T * get() const noexcept
Definition intrusive_shared_ptr.hpp:201
constexpr IntrusiveSharedPtr(const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:67
constexpr T * operator->() const noexcept
Definition intrusive_shared_ptr.hpp:215
friend constexpr bool operator!=(const IntrusiveSharedPtr< T > &lhs, std::nullptr_t) noexcept
Definition intrusive_shared_ptr.hpp:274
friend constexpr bool operator==(const IntrusiveSharedPtr< T > &lhs, std::nullptr_t) noexcept
Definition intrusive_shared_ptr.hpp:253
friend constexpr bool operator==(const IntrusiveSharedPtr< T > &lhs, const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:231
constexpr IntrusiveSharedPtr() noexcept=default
constexpr IntrusiveSharedPtr(T *ptr) noexcept
Definition intrusive_shared_ptr.hpp:50
friend constexpr bool operator!=(std::nullptr_t, const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:285
constexpr IntrusiveSharedPtr(IntrusiveSharedPtr< T > &&rhs) noexcept
Definition intrusive_shared_ptr.hpp:146
constexpr T & operator*() const noexcept
Definition intrusive_shared_ptr.hpp:208
constexpr IntrusiveSharedPtr(const IntrusiveSharedPtr< U > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:81
friend constexpr bool operator!=(const IntrusiveSharedPtr< T > &lhs, const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:243
constexpr IntrusiveSharedPtr< T > & operator=(const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:95