35 template<
typename SharedStorage, concepts::Allocator Alloc>
43 template<
typename SharedStorage, concepts::Allocator Alloc>
55 template<
typename... Args>
64template<concepts::Allocator Alloc = platform::DefaultAllocator>
67 template<
typename, concepts::Allocator>
84 template<
typename Any,
typename T,
typename... Args>
95 auto* pointer = *result;
98 self->m_pointer = pointer;
101 template<
typename T,
typename... Args>
107 self->m_pointer = pointer;
120 dest->m_pointer = source->m_pointer;
121 if (dest->m_pointer) {
123 auto const fp = vtable[
Manage {}];
126 dest->fetch_add_ref_count();
137 template<concepts::VTableFor<Interface> VTable>
141 dest_vtable = source_vtable;
145 template<concepts::VTableFor<Interface> VTable>
149 dest_vtable = source_vtable;
154 if (self->m_pointer) {
155 auto const fp = vtable[
Manage {}];
159 if (self->fetch_sub_ref_count() == 1) {
163 self->m_pointer =
nullptr;
178 constexpr explicit SharedStorage(
void* pointer) : m_pointer(pointer) {}
180 constexpr auto fetch_sub_ref_count() ->
usize {
181 auto& ref_count =
static_cast<detail::RefCount*
>(m_pointer)->ref_count;
185 constexpr auto fetch_add_ref_count() ->
usize {
186 auto& ref_count =
static_cast<detail::RefCount*
>(m_pointer)->ref_count;
190 void* m_pointer {
nullptr };
191 [[no_unique_address]] Alloc m_allocator {};
195 template<
typename SharedStorage, concepts::Allocator Alloc>
203 pointer->ref_count.fetch_add(1);
206 if (pointer->ref_count.fetch_sub(1) == 1) {
Definition operations.h:11
Definition allocator.h:20
Definition vtable_for.h:17
constexpr auto shared_storage_manage
Definition shared_storage.h:44
OpForConsteval
Definition shared_storage.h:29
@ Destroy
Definition shared_storage.h:30
@ RefInc
Definition shared_storage.h:31
@ RefDec
Definition shared_storage.h:32
StorageCategory
Definition storage_category.h:4
@ Copyable
Definition storage_category.h:10
meta::Type< AnyT< UserInterface, Storage, VTablePolicy > > Any
Definition any.h:294
@ Relaxed
Definition memory_order.h:7
@ AcquireRelease
Definition memory_order.h:11
size_t usize
Definition integers.h:33
constexpr auto exchange(T &object, U &&new_value) -> T
Definition exchange.h:8
constexpr auto destroy_at
Definition destroy_at.h:24
constexpr auto construct_at
Definition construct_at.h:27
constexpr auto as_fallible
Definition as_fallible.h:26
constexpr auto try_infallible
Definition try_infallible.h:31
Unexpected(E &&) -> Unexpected< meta::UnwrapRefDecay< E > >
constexpr auto allocate_one
Definition allocate_one.h:29
constexpr auto destroy
Definition destroy.h:35
constexpr auto in_place_type
Definition in_place_type.h:12
constexpr auto deallocate_one
Definition deallocate_one.h:27
Definition shared_storage.h:65
meta::List< Manage > Interface
Definition shared_storage.h:72
static constexpr void copy_construct(concepts::VTableFor< Interface > auto const &vtable, SharedStorage *dest, SharedStorage const *source)
Definition shared_storage.h:118
constexpr auto down_cast() -> T *
Definition shared_storage.h:168
static constexpr void destroy(concepts::VTableFor< Interface > auto &vtable, SharedStorage *self)
Definition shared_storage.h:153
static constexpr auto storage_category() -> StorageCategory
Definition shared_storage.h:74
static constexpr void move_assign(VTable &dest_vtable, SharedStorage *dest, VTable &source_vtable, SharedStorage *source)
Definition shared_storage.h:146
constexpr auto down_cast() const -> T const *
Definition shared_storage.h:173
static constexpr void create(InPlaceType< Any >, meta::LikeExpected< CreationResult< T >, Any > &self, InPlaceType< T >, Args &&... args)
Definition shared_storage.h:86
static constexpr auto init(SharedStorage *self, InPlaceType< T >, Args &&... args)
Definition shared_storage.h:103
static constexpr auto creation_is_fallible(InPlaceType< T >) -> bool
Definition shared_storage.h:77
meta::Type< detail::SharedStorageManage< SharedStorage, Alloc > > Manage
Definition shared_storage.h:71
SharedStorage(SharedStorage const &)=default
auto operator=(SharedStorage const &) -> SharedStorage &=default
meta::AllocatorResult< Alloc > CreationResult
Definition shared_storage.h:82
static constexpr void move_construct(concepts::VTableFor< Interface > auto &vtable, SharedStorage *dest, SharedStorage *source)
Definition shared_storage.h:131
static constexpr void copy_assign(VTable &dest_vtable, SharedStorage *dest, VTable const &source_vtable, SharedStorage const *source)
Definition shared_storage.h:138
Definition shared_storage.h:51
constexpr ObjectWithRefCount(Args &&... args)
Definition shared_storage.h:56
ObjectWithRefCount(ObjectWithRefCount &&)=delete
T object
Definition shared_storage.h:60
constexpr auto to_object_pointer() -> T *
Definition shared_storage.h:58
ObjectWithRefCount(ObjectWithRefCount const &)=delete
Definition shared_storage.h:46
sync::Atomic< usize > ref_count
Definition shared_storage.h:47
Definition shared_storage.h:36
Method< SharedStorageManage, void(This &, SharedStorage *, Alloc &, OpForConsteval)> Type
Definition shared_storage.h:37
constexpr void operator()(T &, SharedStorage *, Alloc &, OpForConsteval) const
Definition shared_storage.h:197
Definition in_place_type.h:5