1#ifndef NEFORCE_CORE_MEMORY_ALLOCATOR_TRAITS_HPP__
2#define NEFORCE_CORE_MEMORY_ALLOCATOR_TRAITS_HPP__
14NEFORCE_BEGIN_NAMESPACE__
31struct __allocator_traits_base {
37 template <
typename T,
typename U,
typename =
void>
47 template <
typename T,
typename U>
48 struct alloc_rebind<T, U,
void_t<typename T::template rebind<U>::other>> {
49 using type =
typename T::template rebind<U>::other;
55 template <
typename T,
typename U>
56 using alloc_rebind_t =
typename alloc_rebind<T, U>::type;
60 using __pointer =
typename T::pointer;
62 using __c_pointer =
typename T::const_pointer;
81template <
typename Alloc>
83 using allocator_type = Alloc;
84 using value_type =
typename Alloc::value_type;
88 template <
template <
typename>
class Func,
typename T,
typename =
void>
93 template <
template <
typename>
class Func,
typename T>
94 struct real_ptr<Func, T,
void_t<Func<Alloc>>> {
95 using type = Func<Alloc>;
98 template <
typename,
typename Ptr,
typename =
void>
103 template <
typename AllocU,
typename Ptr>
105 using type =
typename AllocU::difference_type;
108 template <
typename,
typename Diff,
typename =
void>
111 template <
typename AllocU,
typename Diff>
113 using type =
typename AllocU::size_type;
117 using const_pointer =
typename real_ptr<__c_pointer, const value_type>::type;
119 using size_type =
typename real_size<Alloc, difference_type>::type;
125 template <
typename T>
132 template <
typename T>
136 template <
typename T,
typename... Args>
138 __construct_aux(Alloc& alloc, T* ptr,
139 Args&&... args)
noexcept(
noexcept(alloc.construct(ptr, _NEFORCE
forward<Args>(args)...))) {
143 template <
typename T,
typename... Args>
150 template <
typename Alloc2,
typename T>
151 static constexpr auto __destroy_aux(Alloc2& alloc, T* ptr,
int)
noexcept(
noexcept(alloc.destroy(ptr)))
152 ->
decltype(alloc.destroy(ptr)) {
156 template <
typename Alloc2,
typename T>
161 template <
typename Alloc2>
162 static constexpr auto __max_size_aux(Alloc2& alloc,
int)
noexcept(
noexcept(alloc.max_size()))
163 ->
decltype(alloc.max_size()) {
164 return alloc.max_size();
167 template <
typename Alloc2>
168 static constexpr size_type __max_size_aux(Alloc2&, ...) noexcept {
180 return alloc.allocate(n);
189 static NEFORCE_CONSTEXPR20
void deallocate(Alloc& alloc, pointer ptr,
size_type n) { alloc.deallocate(ptr, n); }
199 template <
typename T,
typename... Args>
200 static NEFORCE_CONSTEXPR20
void construct(Alloc& alloc, T* ptr, Args&&... args)
noexcept(
201 noexcept(allocator_traits::__construct_aux(alloc, ptr, _NEFORCE
forward<Args>(args)...))) {
202 allocator_traits::__construct_aux(alloc, ptr, _NEFORCE
forward<Args>(args)...);
211 template <
typename T>
212 static NEFORCE_CONSTEXPR20
void destroy(Alloc& alloc,
213 T* ptr)
noexcept(
noexcept(allocator_traits::__destroy_aux(alloc, ptr, 0))) {
214 allocator_traits::__destroy_aux(alloc, ptr, 0);
223 max_size(
const Alloc& alloc)
noexcept(
noexcept(allocator_traits::__max_size_aux(alloc, 0))) {
224 return allocator_traits::__max_size_aux(alloc, 0);
230NEFORCE_END_NAMESPACE__
static NEFORCE_NODISCARD constexpr T max() noexcept
获取类型的最大值
NEFORCE_NODISCARD constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
typename replace_first_para< T, U >::type replace_first_para_t
replace_first_para的便捷别名
NEFORCE_INLINE17 constexpr bool has_construct_v
has_construct的便捷变量模板
typename detected_or< Default, Op, Args... >::type detected_or_t
detected_or的便捷别名,返回检测到的类型或默认类型
NEFORCE_INLINE17 constexpr bool is_nothrow_destructible_v
is_nothrow_destructible的便捷变量模板
NEFORCE_INLINE17 constexpr bool conjunction_v
conjunction的便捷变量模板
typename enable_if< Test, T >::type enable_if_t
enable_if的便捷别名
typename real_size< Alloc, difference_type >::type size_type
大小类型
typename real_ptr< __c_pointer, const value_type >::type const_pointer
常量指针类型
static NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 pointer allocate(Alloc &alloc, size_type n)
分配内存
static NEFORCE_CONSTEXPR20 size_type max_size(const Alloc &alloc) noexcept(noexcept(allocator_traits::__max_size_aux(alloc, 0)))
获取分配器支持的最大大小
static NEFORCE_CONSTEXPR20 void deallocate(Alloc &alloc, pointer ptr, size_type n)
释放内存
typename real_diff< Alloc, pointer >::type difference_type
指针差异类型
alloc_rebind< Alloc, T > rebind_alloc
重新绑定分配器类型
allocator_traits< rebind_alloc< T > > rebind_traits
重新绑定分配器特性类型
static NEFORCE_CONSTEXPR20 void destroy(Alloc &alloc, T *ptr) noexcept(noexcept(allocator_traits::__destroy_aux(alloc, ptr, 0)))
销毁对象
static NEFORCE_CONSTEXPR20 void construct(Alloc &alloc, T *ptr, Args &&... args) noexcept(noexcept(allocator_traits::__construct_aux(alloc, ptr, _NEFORCE forward< Args >(args)...)))
在已分配内存上构造对象