6 #ifndef METALL_STL_ALLOCATOR_HPP
7 #define METALL_STL_ALLOCATOR_HPP
10 #include <type_traits>
33 template <
typename T,
typename metall_manager_kernel_type>
40 using pointer =
typename std::pointer_traits<
41 typename metall_manager_kernel_type::void_pointer>::
46 typename std::pointer_traits<pointer>::template
rebind<void>;
50 typename std::pointer_traits<pointer>::difference_type;
51 using size_type =
typename std::make_unsigned<difference_type>::type;
56 template <
typename T2>
77 : m_ptr_manager_kernel_address(pointer_manager_kernel_address) {}
80 template <
typename T2>
83 : m_ptr_manager_kernel_address(
84 allocator_instance.get_pointer_to_manager_kernel()) {}
99 template <typename T2>
102 m_ptr_manager_kernel_address = other.m_ptr_manager_kernel_address;
110 template <
typename T2>
113 m_ptr_manager_kernel_address = other.m_ptr_manager_kernel_address;
126 return priv_deallocate(ptr, size);
137 template <
class... Args>
139 priv_construct(ptr, std::forward<Args>(args)...);
150 return to_raw_pointer(m_ptr_manager_kernel_address);
159 if (priv_max_size() < n) {
160 throw std::bad_array_new_length();
165 "nullptr: cannot access to manager kernel");
166 throw std::bad_alloc();
169 if (!manager_kernel) {
171 "nullptr: cannot access to manager kernel");
172 throw std::bad_alloc();
176 static_cast<value_type *
>(manager_kernel->allocate(n *
sizeof(T))));
178 throw std::bad_alloc();
184 void priv_deallocate(
pointer ptr,
185 [[maybe_unused]]
const size_type size)
const noexcept {
188 "nullptr: cannot access to manager kernel");
192 if (!manager_kernel) {
194 "nullptr: cannot access to manager kernel");
197 manager_kernel->deallocate(to_raw_pointer(ptr));
200 size_type priv_max_size() const noexcept {
201 return std::numeric_limits<size_type>::max() /
sizeof(
value_type);
204 template <
class... arg_types>
205 void priv_construct(
const pointer &ptr, arg_types &&...args)
const {
206 ::new ((
void *)to_raw_pointer(ptr))
210 void priv_destroy(
const pointer &ptr)
const {
213 "pointer is nullptr");
215 (*ptr).~value_type();
224 typename std::pointer_traits<typename manager_kernel_type::void_pointer>::
225 template rebind<manager_kernel_type *const>
226 m_ptr_manager_kernel_address;
229 template <
typename T,
typename kernel>
237 template <
typename T,
typename kernel>
240 return !(rhd == lhd);