1#ifndef MSTL_CORE_MEMORY_ALLOCATOR_TRAITS_HPP__
2#define MSTL_CORE_MEMORY_ALLOCATOR_TRAITS_HPP__
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>
137 static constexpr enable_if_t<has_construct_v<Alloc, T, Args...>>
138 __construct_aux(Alloc& alloc, T* ptr, Args&&... args)
143 template <
typename T,
typename... Args>
146 __construct_aux(Alloc&, T* ptr, Args&&... args)
151 template <
typename Alloc2,
typename T>
152 static constexpr auto __destroy_aux(Alloc2& alloc, T* ptr,
int)
153 noexcept(
noexcept(alloc.destroy(ptr))) ->
decltype(alloc.destroy(ptr)) {
157 template <
typename Alloc2,
typename T>
158 static constexpr void __destroy_aux(Alloc2&, T* ptr, ...)
159 noexcept(is_nothrow_destructible_v<T>) {
163 template <
typename Alloc2>
164 static constexpr auto __max_size_aux(Alloc2& alloc,
int)
165 noexcept(
noexcept(alloc.max_size()))
166 ->
decltype(alloc.max_size()) {
167 return alloc.max_size();
170 template <
typename Alloc2>
171 static constexpr size_type __max_size_aux(Alloc2&, ...) noexcept {
183 return alloc.allocate(n);
193 alloc.deallocate(ptr, n);
204 template <
typename T,
typename... Args>
205 static MSTL_CONSTEXPR20
void construct(Alloc& alloc, T* ptr, Args&&... args)
206 noexcept(
noexcept(allocator_traits::__construct_aux(alloc, ptr,
_MSTL forward<Args>(args)...))) {
216 template <
typename T>
217 static MSTL_CONSTEXPR20
void destroy(Alloc& alloc, T* ptr)
218 noexcept(
noexcept(allocator_traits::__destroy_aux(alloc, ptr, 0))) {
219 allocator_traits::__destroy_aux(alloc, ptr, 0);
228 noexcept(
noexcept(allocator_traits::__max_size_aux(alloc, 0))) {
229 return allocator_traits::__max_size_aux(alloc, 0);
static MSTL_NODISCARD constexpr T max() noexcept
获取类型的最大值
MSTL_NODISCARD constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_INNER__
结束inner命名空间
#define _INNER
inner命名空间前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
#define MSTL_BEGIN_INNER__
开始inner命名空间
typename replace_first_para< T, U >::type replace_first_para_t
replace_first_para的便捷别名
typename detected_or< Default, Op, Args... >::type detected_or_t
detected_or的便捷别名,返回检测到的类型或默认类型
typename enable_if< Test, T >::type enable_if_t
enable_if的便捷别名
typename real_size< Alloc, difference_type >::type size_type
大小类型
static MSTL_CONSTEXPR20 size_type max_size(const Alloc &alloc) noexcept(noexcept(allocator_traits::__max_size_aux(alloc, 0)))
获取分配器支持的最大大小
typename real_ptr< __c_pointer, const value_type >::type const_pointer
常量指针类型
static MSTL_CONSTEXPR20 void destroy(Alloc &alloc, T *ptr) noexcept(noexcept(allocator_traits::__destroy_aux(alloc, ptr, 0)))
销毁对象
static MSTL_NODISCARD MSTL_CONSTEXPR20 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 MSTL_CONSTEXPR20 void deallocate(Alloc &alloc, pointer ptr, size_type n)
释放内存
static MSTL_CONSTEXPR20 void construct(Alloc &alloc, T *ptr, Args &&... args) noexcept(noexcept(allocator_traits::__construct_aux(alloc, ptr, _MSTL forward< Args >(args)...)))
在已分配内存上构造对象