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>
146 __construct_aux(Alloc& , T* ptr,
151 template <
typename Alloc2,
typename T>
152 static constexpr auto __destroy_aux(Alloc2& alloc, T* ptr,
int )
noexcept(
noexcept(alloc.destroy(ptr)))
153 ->
decltype(alloc.destroy(ptr)) {
157 template <
typename Alloc2,
typename T>
162 template <
typename Alloc2>
163 static constexpr auto __max_size_aux(Alloc2& alloc,
int )
noexcept(
noexcept(alloc.max_size()))
164 ->
decltype(alloc.max_size()) {
165 return alloc.max_size();
168 template <
typename Alloc2>
169 static constexpr size_type __max_size_aux(Alloc2& , ...) noexcept {
181 return alloc.allocate(n);
190 static NEFORCE_CONSTEXPR20
void deallocate(Alloc& alloc, pointer ptr,
size_type n) { alloc.deallocate(ptr, n); }
200 template <
typename T,
typename... Args>
201 static NEFORCE_CONSTEXPR20
void construct(Alloc& alloc, T* ptr, Args&&... args)
noexcept(
202 noexcept(allocator_traits::__construct_aux(alloc, ptr, _NEFORCE
forward<Args>(args)...))) {
203 allocator_traits::__construct_aux(alloc, ptr, _NEFORCE
forward<Args>(args)...);
212 template <
typename T>
213 static NEFORCE_CONSTEXPR20
void destroy(Alloc& alloc,
214 T* ptr)
noexcept(
noexcept(allocator_traits::__destroy_aux(alloc, ptr, 0))) {
215 allocator_traits::__destroy_aux(alloc, ptr, 0);
224 max_size(
const Alloc& alloc)
noexcept(
noexcept(allocator_traits::__max_size_aux(alloc, 0))) {
225 return allocator_traits::__max_size_aux(alloc, 0);
231NEFORCE_END_NAMESPACE__
static constexpr T max() noexcept
获取类型的最大值
constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
typename replace_first_para< T, U >::type replace_first_para_t
replace_first_para的便捷别名
constexpr bool has_construct_v
has_construct的便捷变量模板
typename detected_or< Default, Op, Args... >::type detected_or_t
detected_or的便捷别名,返回检测到的类型或默认类型
constexpr bool is_nothrow_destructible_v
is_nothrow_destructible的便捷变量模板
constexpr bool conjunction_v
conjunction的便捷变量模板
typename enable_if< Test, T >::type enable_if_t
enable_if的便捷别名
static constexpr void deallocate(Alloc &alloc, pointer ptr, size_type n)
释放内存
static constexpr void destroy(Alloc &alloc, T *ptr) noexcept(noexcept(allocator_traits::__destroy_aux(alloc, ptr, 0)))
销毁对象
typename real_size< Alloc, difference_type >::type size_type
大小类型
static constexpr void construct(Alloc &alloc, T *ptr, Args &&... args) noexcept(noexcept(allocator_traits::__construct_aux(alloc, ptr, _NEFORCE forward< Args >(args)...)))
在已分配内存上构造对象
typename real_ptr< __c_pointer, const value_type >::type const_pointer
常量指针类型
static constexpr pointer allocate(Alloc &alloc, 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 constexpr size_type max_size(const Alloc &alloc) noexcept(noexcept(allocator_traits::__max_size_aux(alloc, 0)))
获取分配器支持的最大大小