12#include <lagrange/internal/smart_ptr/default_delete.h>
13#include <lagrange/internal/smart_ptr/ptr.h>
28 virtual void inc_ref()
noexcept = 0;
29 virtual void inc_wref()
noexcept = 0;
30 virtual void dec_ref()
noexcept = 0;
31 virtual void dec_wref()
noexcept = 0;
33 virtual long use_count()
const noexcept = 0;
34 virtual bool unique()
const noexcept = 0;
35 virtual long weak_use_count()
const noexcept = 0;
36 virtual bool expired()
const noexcept = 0;
38 virtual void* get_deleter()
noexcept = 0;
50template <
typename T,
typename D = default_delete<T>>
54 using element_type = T;
55 using deleter_type = D;
74 void inc_ref()
noexcept override { ++_use_count; }
76 void inc_wref()
noexcept override { ++_weak_use_count; }
78 void dec_ref()
noexcept override
80 auto _ptr = _impl._impl_ptr();
81 auto& _deleter = _impl._impl_deleter();
82 if (--_use_count == 0) {
83 if (_ptr) _deleter(_ptr);
88 void dec_wref()
noexcept override
90 if (--_weak_use_count == 0) {
97 long use_count()
const noexcept override
102 bool unique()
const noexcept override {
return _use_count == 1; }
104 long weak_use_count()
const noexcept override
106 return _weak_use_count - ((_use_count > 0) ? 1 : 0);
109 bool expired()
const noexcept override {
return _use_count == 0; }
111 void* get_deleter()
noexcept override
113 return reinterpret_cast<void*
>(std::addressof(_impl._impl_deleter()));
117 std::atomic<long> _use_count{1};
120 std::atomic<long> _weak_use_count{1};
Definition: control_block.h:24
NOT implemented: custom allocator support.
Definition: control_block.h:52
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition: attribute_string_utils.h:21