1 #ifndef CYCLE_PTR_DETAIL_CONTROL_H 2 #define CYCLE_PTR_DETAIL_CONTROL_H 9 #include <cycle_ptr/detail/base_control.h> 10 #include <cycle_ptr/detail/generation.h> 12 namespace cycle_ptr::detail {
23 template<
typename T,
typename Alloc>
28 using alloc_traits = std::allocator_traits<Alloc>;
29 using control_alloc_t =
typename alloc_traits::template rebind_alloc<control>;
30 using control_alloc_traits_t =
typename alloc_traits::template rebind_traits<control>;
32 static_assert(std::is_same_v<typename alloc_traits::value_type, T>,
33 "Alloc must be allocator of T.");
41 : Alloc(std::move(alloc))
51 template<
typename... Args>
56 publisher pub{ reinterpret_cast<void*>(&store_),
sizeof(store_), *
this };
57 new (reinterpret_cast<void*>(&store_)) T(std::forward<Args>(args)...);
62 return reinterpret_cast<T*>(&store_);
73 reinterpret_cast<T*>(&store_)->~T();
78 auto get_deleter_() const
81 return &deleter_impl_;
89 assert(bc !=
nullptr);
91 control* ptr = static_cast<control*>(bc);
93 control* ptr = dynamic_cast<control*>(bc);
94 assert(ptr !=
nullptr);
97 control_alloc_t alloc = std::move(*ptr);
98 control_alloc_traits_t::destroy(alloc, ptr);
99 control_alloc_traits_t::deallocate(alloc, ptr, 1);
103 std::aligned_storage_t<
sizeof(T),
alignof(T)> store_;
control(Alloc alloc)
Create control block.
Definition: control.h:40
bool under_construction
This variable indicates the managed object is under construction.
Definition: base_control.h:204
Address range publisher.
Definition: base_control.h:215
base_control()
Default constructor allocates a new generation.
auto instantiate(Args &&... args) -> T *
Instantiate the object managed by this control block.
Definition: control.h:52
Control block implementation for given type and allocator combination.
Definition: control.h:24
Base class for all control blocks.
Definition: base_control.h:30