52 if (m_ptr !=
nullptr) {
57 constexpr ~IntrusiveSharedPtr() {
58 if (m_ptr !=
nullptr) {
70 if (m_ptr !=
nullptr) {
81 requires(!std::same_as<T, U> && std::convertible_to<U*, T*>)
85 if (m_ptr !=
nullptr) {
99 if (m_ptr ==
rhs.m_ptr) {
103 if (m_ptr !=
nullptr) {
104 dec_ref_count(m_ptr);
109 if (m_ptr !=
nullptr) {
110 inc_ref_count(m_ptr);
122 template <
typename U>
123 requires(!std::same_as<T, U> && std::convertible_to<U*, T*>)
127 if (m_ptr ==
rhs.m_ptr) {
131 if (m_ptr !=
nullptr) {
132 dec_ref_count(m_ptr);
137 if (m_ptr !=
nullptr) {
138 inc_ref_count(m_ptr);
150 : m_ptr{std::exchange(
rhs.m_ptr,
nullptr)} {}
157 template <
typename U>
158 requires(!std::same_as<T, U> && std::convertible_to<U*, T*>)
161 : m_ptr{std::exchange(
rhs.m_ptr,
nullptr)} {}
171 if (m_ptr ==
rhs.m_ptr) {
175 std::swap(m_ptr,
rhs.m_ptr);
186 template <
typename U>
187 requires(!std::same_as<T, U> && std::convertible_to<U*, T*>)
190 if (m_ptr ==
rhs.m_ptr) {
194 std::swap(m_ptr,
rhs.m_ptr);
236 return lhs.m_ptr ==
rhs.m_ptr;
248 return lhs.m_ptr !=
rhs.m_ptr;
257 std::nullptr_t)
noexcept {
258 return lhs.m_ptr ==
nullptr;
268 return nullptr ==
rhs.m_ptr;
278 std::nullptr_t)
noexcept {
279 return lhs.m_ptr !=
nullptr;
290 return nullptr !=
rhs.m_ptr;
305template <
typename T,
typename... Args>
306IntrusiveSharedPtr<T> make_intrusive_shared(Args&&... args) {
307 return IntrusiveSharedPtr<T>{
new T(std::forward<Args>(args)...)};
321template <
typename T,
typename Alloc,
typename... Args>
322IntrusiveSharedPtr<T> allocate_intrusive_shared(Alloc alloc, Args&&... args) {
323 auto ptr = std::allocator_traits<Alloc>::allocate(alloc,
sizeof(T));
324 std::allocator_traits<Alloc>::construct(alloc, ptr,
325 std::forward<Args>(args)...);
326 return IntrusiveSharedPtr<T>{ptr};
Definition intrusive_shared_ptr.hpp:29
constexpr IntrusiveSharedPtr(IntrusiveSharedPtr< U > &&rhs) noexcept
Definition intrusive_shared_ptr.hpp:160
constexpr IntrusiveSharedPtr< T > & operator=(IntrusiveSharedPtr< T > &&rhs) noexcept
Definition intrusive_shared_ptr.hpp:169
friend constexpr bool operator==(std::nullptr_t, const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:266
constexpr T * get() const noexcept
Definition intrusive_shared_ptr.hpp:204
constexpr IntrusiveSharedPtr(const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:68
constexpr T * operator->() const noexcept
Definition intrusive_shared_ptr.hpp:218
friend constexpr bool operator!=(const IntrusiveSharedPtr< T > &lhs, std::nullptr_t) noexcept
Definition intrusive_shared_ptr.hpp:277
friend constexpr bool operator==(const IntrusiveSharedPtr< T > &lhs, std::nullptr_t) noexcept
Definition intrusive_shared_ptr.hpp:256
friend constexpr bool operator==(const IntrusiveSharedPtr< T > &lhs, const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:234
constexpr IntrusiveSharedPtr() noexcept=default
constexpr IntrusiveSharedPtr(T *ptr) noexcept
Definition intrusive_shared_ptr.hpp:51
friend constexpr bool operator!=(std::nullptr_t, const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:288
constexpr IntrusiveSharedPtr(IntrusiveSharedPtr< T > &&rhs) noexcept
Definition intrusive_shared_ptr.hpp:149
constexpr T & operator*() const noexcept
Definition intrusive_shared_ptr.hpp:211
constexpr IntrusiveSharedPtr(const IntrusiveSharedPtr< U > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:83
friend constexpr bool operator!=(const IntrusiveSharedPtr< T > &lhs, const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:246
constexpr IntrusiveSharedPtr< T > & operator=(const IntrusiveSharedPtr< T > &rhs) noexcept
Definition intrusive_shared_ptr.hpp:97