4#ifndef WPI_MEMORY_ALLOCATOR_TRAITS_HPP_INCLUDED
5#define WPI_MEMORY_ALLOCATOR_TRAITS_HPP_INCLUDED
17#if WPI_HOSTED_IMPLEMENTATION
27 template <
class Allocator>
29 std::declval<typename Allocator::pointer>(),
30 std::declval<typename Allocator::value_type>())));
32 template <
class Allocator>
35 template <
class Allocator>
37 std::declval<typename Allocator::pointer>())));
39 template <
class Allocator>
42 template <
class Allocator>
48 using valid = std::integral_constant<bool, !custom_construct::value
49 && !custom_destroy::value>;
58 template <
class Allocator>
60 : WPI_EBO(detail::check_standard_allocator<Allocator>::valid)
71 namespace traits_detail
77 operator void*()
const noexcept
80 "this is just to hide an error and move static_assert to the front");
98 static const bool error =
false;
105 template <
class Allocator>
106 auto rebind_impl(
int) ->
typename Allocator::template rebind<char>::other&;
108 template <
class Allocator,
typename T>
114 template <
template <
typename,
typename...>
class Alloc,
typename U,
typename... Args,
118 using type = Alloc<T, Args...>&;
121 template <
class Allocator,
typename =
typename Allocator::value_type>
124 template <
class Allocator>
127 template <
class Allocator>
133 template <
class Allocator>
135 typename std::decay<typename allocator_type_impl<Allocator>::type>::type;
140 template <
class Allocator>
143 template <
class Allocator,
bool IsEmpty>
146 template <
class Allocator>
149 static_assert(std::is_default_constructible<Allocator>::value,
150 "RawAllocator is empty but not default constructible ."
151 "This means it is not a stateless allocator. "
152 "If this is actually intended provide the appropriate is_stateful "
153 "typedef in your class.");
157 template <
class Allocator>
163 template <
class Allocator>
171 template <
class Allocator>
173 std::size_t alignment)
176 template <
class Allocator>
180 template <
class Allocator>
184 "type is not a RawAllocator as it does not provide: void* "
185 "allocate_node(std::size_t, "
194 template <
class Allocator>
196 std::size_t alignment)
noexcept
199 template <
class Allocator>
201 std::size_t)
noexcept
204 template <
class Allocator>
208 "type is not a RawAllocator as it does not provide: void "
209 "deallocate_node(void*, std::size_t, "
217 template <
class Allocator>
219 std::size_t alignment)
222 template <
class Allocator>
224 std::size_t size, std::size_t alignment)
232 template <
class Allocator>
234 std::size_t size, std::size_t alignment)
noexcept
238 template <
class Allocator>
240 std::size_t count, std::size_t size,
241 std::size_t alignment)
noexcept
249 template <
class Allocator>
253 template <
class Allocator>
256 return std::size_t(-1);
262 template <
class Allocator>
266 template <
class Allocator>
275 template <
class Allocator>
279 template <
class Allocator>
290 template <
class Allocator>
299 std::size_t alignment)
302 "Allocator cannot be used as RawAllocator because it provides custom "
303 "construct()/destroy()");
309 std::size_t alignment)
312 "Allocator cannot be used as RawAllocator because it provides custom "
313 "construct()/destroy()");
319 std::size_t alignment)
noexcept
322 "Allocator cannot be used as RawAllocator because it provides custom "
323 "construct()/destroy()");
329 std::size_t size, std::size_t alignment)
noexcept
332 "Allocator cannot be used as RawAllocator because it provides custom "
333 "construct()/destroy()");
341 "Allocator cannot be used as RawAllocator because it provides custom "
342 "construct()/destroy()");
349 "Allocator cannot be used as RawAllocator because it provides custom "
350 "construct()/destroy()");
357 "Allocator cannot be used as RawAllocator because it provides custom "
358 "construct()/destroy()");
363 using foonathan_memory_default_traits = std::true_type;
369 template <
class RawAllocator>
370 typename allocator_traits<RawAllocator>::foonathan_memory_default_traits
375 template <
typename T>
378 decltype(traits_detail::allocate_node(traits_detail::full_concept{},
379 std::declval<typename allocator_traits<
380 T>::allocator_type&>(),
382 traits_detail::error>
386 template <
typename T>
389 decltype(traits_detail::deallocate_node(traits_detail::full_concept{},
390 std::declval<typename allocator_traits<
391 T>::allocator_type&>(),
393 traits_detail::error>
397 template <
typename T,
class DefaultTraits>
402 template <
typename T>
404 : std::integral_constant<bool, allocator_is_raw_allocator<T>::value
405 && !(has_invalid_alloc_function<T>::value
406 || has_invalid_dealloc_function<T>::value)>
414 template <
typename T>
417 decltype(detail::alloc_uses_default_traits(std::declval<T&>()))>
421 namespace traits_detail
426 template <
class Allocator>
428 std::size_t alignment)
noexcept
431 template <
class Allocator>
435 "type is not a composable RawAllocator as it does not provide: void* "
436 "try_allocate_node(std::size_t, "
444 template <
class Allocator>
446 std::size_t alignment)
noexcept
449 template <
class Allocator>
453 "type is not a composable RawAllocator as it does not provide: bool "
454 "try_deallocate_node(void*, std::size_t, "
462 template <
class Allocator>
464 std::size_t size, std::size_t alignment)
noexcept
468 template <
class Allocator>
470 std::size_t size, std::size_t alignment)
478 template <
class Allocator>
480 std::size_t size, std::size_t alignment)
noexcept
485 template <
class Allocator>
487 std::size_t count, std::size_t size,
488 std::size_t alignment)
noexcept
498 template <
class Allocator>
505 std::size_t alignment)
noexcept
508 "ComposableAllocator must be RawAllocator");
514 std::size_t size, std::size_t alignment)
noexcept
517 "ComposableAllocator must be RawAllocator");
519 count, size, alignment);
523 std::size_t alignment)
noexcept
526 "ComposableAllocator must be RawAllocator");
528 node, size, alignment);
532 std::size_t size, std::size_t alignment)
noexcept
535 "ComposableAllocator must be RawAllocator");
537 array, count, size, alignment);
541 using foonathan_memory_default_traits = std::true_type;
547 template <
class RawAllocator>
548 typename composable_allocator_traits<RawAllocator>::foonathan_memory_default_traits
553 template <
typename T>
556 decltype(traits_detail::try_allocate_node(traits_detail::full_concept{},
557 std::declval<typename allocator_traits<
558 T>::allocator_type&>(),
560 traits_detail::error>
564 template <
typename T>
566 : std::is_same<decltype(traits_detail::
567 try_deallocate_node(traits_detail::full_concept{},
568 std::declval<typename allocator_traits<
569 T>::allocator_type&>(),
571 traits_detail::error>
575 template <
typename T,
class DefaultTraits>
580 template <
typename T>
582 : std::integral_constant<bool, memory::is_raw_allocator<T>::value
583 && !(has_invalid_try_alloc_function<T>::value
584 || has_invalid_try_dealloc_function<T>::value)>
592 template <
typename T>
595 std::declval<T&>()))>
This class is a wrapper around std::array that does compile time size checking.
Definition array.h:26
The default specialization of the allocator_traits for a RawAllocator.
Definition allocator_traits.hpp:292
static void deallocate_array(allocator_type &state, void *array, std::size_t count, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:328
traits_detail::allocator_type< Allocator > allocator_type
Definition allocator_traits.hpp:294
static void * allocate_array(allocator_type &state, std::size_t count, std::size_t size, std::size_t alignment)
Definition allocator_traits.hpp:308
static std::size_t max_array_size(const allocator_type &state)
Definition allocator_traits.hpp:346
static std::size_t max_node_size(const allocator_type &state)
Definition allocator_traits.hpp:338
static std::size_t max_alignment(const allocator_type &state)
Definition allocator_traits.hpp:354
static void * allocate_node(allocator_type &state, std::size_t size, std::size_t alignment)
Definition allocator_traits.hpp:298
static void deallocate_node(allocator_type &state, void *node, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:318
decltype(traits_detail::is_stateful< Allocator >(traits_detail::full_concept{})) is_stateful
Definition allocator_traits.hpp:295
The default specialization of the composable_allocator_traits for a ComposableAllocator.
Definition allocator_traits.hpp:500
static void * try_allocate_node(allocator_type &state, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:504
typename allocator_traits< Allocator >::allocator_type allocator_type
Definition allocator_traits.hpp:502
static void * try_allocate_array(allocator_type &state, std::size_t count, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:513
static bool try_deallocate_node(allocator_type &state, void *node, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:522
static bool try_deallocate_array(allocator_type &state, void *array, std::size_t count, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:531
detail namespace with internal helper functions
Definition input_adapters.h:32
Implement std::hash so that hash_code can be used in STL containers.
Definition PointerIntPair.h:280
std::true_type has_construct(int,)
void construct(std::true_type, T *cur, T *end, Args &&... args)
Definition smart_ptr.hpp:45
std::true_type has_destroy(int,)
composable_allocator_traits< RawAllocator >::foonathan_memory_default_traits composable_alloc_uses_default_traits(RawAllocator &)
constexpr std::size_t max_alignment
Definition align.hpp:42
allocator_traits< RawAllocator >::foonathan_memory_default_traits alloc_uses_default_traits(RawAllocator &)
auto is_stateful(full_concept) -> decltype(typename Allocator::is_stateful{})
auto allocate_array(full_concept, Allocator &alloc, std::size_t count, std::size_t size, std::size_t alignment) -> WPI_AUTO_RETURN_TYPE(alloc.allocate_array(count, size, alignment), void *) template< class Allocator > void *allocate_array(min_concept, Allocator &alloc, std::size_t count, std::size_t size, std::size_t alignment)
Definition allocator_traits.hpp:218
auto allocate_node(full_concept, Allocator &alloc, std::size_t size, std::size_t alignment) -> WPI_AUTO_RETURN_TYPE(alloc.allocate_node(size, alignment), void *) template< class Allocator > auto allocate_node(std_concept, Allocator &alloc, std::size_t size, std::size_t) -> WPI_AUTO_RETURN(static_cast< void * >(alloc.allocate(size))) template< class Allocator > error allocate_node(error, Allocator &, std::size_t, std::size_t)
Definition allocator_traits.hpp:172
typename std::decay< typename allocator_type_impl< Allocator >::type >::type allocator_type
Definition allocator_traits.hpp:134
auto try_deallocate_node(full_concept, Allocator &alloc, void *ptr, std::size_t size, std::size_t alignment) noexcept -> WPI_AUTO_RETURN_TYPE(alloc.try_deallocate_node(ptr, size, alignment), bool) template< class Allocator > error try_deallocate_node(error, Allocator &, void *, std::size_t, std::size_t)
Definition allocator_traits.hpp:445
auto try_allocate_array(full_concept, Allocator &alloc, std::size_t count, std::size_t size, std::size_t alignment) noexcept -> WPI_AUTO_RETURN_TYPE(alloc.try_allocate_array(count, size, alignment), void *) template< class Allocator > void *try_allocate_array(min_concept, Allocator &alloc, std::size_t count, std::size_t size, std::size_t alignment)
Definition allocator_traits.hpp:463
auto deallocate_array(full_concept, Allocator &alloc, void *ptr, std::size_t count, std::size_t size, std::size_t alignment) noexcept -> WPI_AUTO_RETURN_TYPE(alloc.deallocate_array(ptr, count, size, alignment), void) template< class Allocator > void deallocate_array(min_concept, Allocator &alloc, void *ptr, std::size_t count, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:233
auto max_alignment(full_concept, const Allocator &alloc) -> WPI_AUTO_RETURN_TYPE(alloc.max_alignment(), std::size_t) template< class Allocator > std::size_t max_alignment(min_concept, const Allocator &)
Definition allocator_traits.hpp:276
auto rebind_impl(int) -> typename Allocator::template rebind< char >::other &
auto try_deallocate_array(full_concept, Allocator &alloc, void *ptr, std::size_t count, std::size_t size, std::size_t alignment) noexcept -> WPI_AUTO_RETURN_TYPE(alloc.try_deallocate_array(ptr, count, size, alignment), bool) template< class Allocator > bool try_deallocate_array(min_concept, Allocator &alloc, void *ptr, std::size_t count, std::size_t size, std::size_t alignment) noexcept
Definition allocator_traits.hpp:479
auto try_allocate_node(full_concept, Allocator &alloc, std::size_t size, std::size_t alignment) noexcept -> WPI_AUTO_RETURN_TYPE(alloc.try_allocate_node(size, alignment), void *) template< class Allocator > error try_allocate_node(error, Allocator &, std::size_t, std::size_t)
Definition allocator_traits.hpp:427
auto deallocate_node(full_concept, Allocator &alloc, void *ptr, std::size_t size, std::size_t alignment) noexcept -> WPI_AUTO_RETURN_TYPE(alloc.deallocate_node(ptr, size, alignment), void) template< class Allocator > auto deallocate_node(std_concept, Allocator &alloc, void *ptr, std::size_t size, std::size_t) noexcept -> WPI_AUTO_RETURN_TYPE(alloc.deallocate(static_cast< char * >(ptr), size), void) template< class Allocator > error deallocate_node(error, Allocator &, void *, std::size_t, std::size_t)
Definition allocator_traits.hpp:195
auto max_node_size(full_concept, const Allocator &alloc) -> WPI_AUTO_RETURN_TYPE(alloc.max_node_size(), std::size_t) template< class Allocator > std::size_t max_node_size(min_concept, const Allocator &) noexcept
Definition allocator_traits.hpp:250
auto max_array_size(full_concept, const Allocator &alloc) -> WPI_AUTO_RETURN_TYPE(alloc.max_array_size(), std::size_t) template< class Allocator > std::size_t max_array_size(min_concept, const Allocator &alloc)
Definition allocator_traits.hpp:263
Memory namespace.
Definition heap_allocator.hpp:20
Foonathan namespace.
Definition ntcore_cpp.h:26
array(T, Ts...) -> array< T, 1+sizeof...(Ts)>
Traits class that checks whether or not a standard Allocator can be used as RawAllocator.
Definition allocator_traits.hpp:61
Definition allocator_traits.hpp:44
decltype(has_construct< Allocator >(0)) custom_construct
Definition allocator_traits.hpp:45
decltype(has_destroy< Allocator >(0)) custom_destroy
Definition allocator_traits.hpp:46
std::integral_constant< bool, !custom_construct::value &&!custom_destroy::value > valid
Definition allocator_traits.hpp:48
Definition allocator_traits.hpp:383
Definition allocator_traits.hpp:394
Definition allocator_traits.hpp:561
Definition allocator_traits.hpp:572
Definition allocator_traits.hpp:577
Definition allocator_traits.hpp:399
Traits that check whether a type models concept ComposableAllocator.
Definition allocator_traits.hpp:596
Traits that check whether a type models concept RawAllocator.
Definition allocator_traits.hpp:418
Alloc< T, Args... > & type
Definition allocator_traits.hpp:118
Definition allocator_traits.hpp:110
Allocator & type
Definition allocator_traits.hpp:111
Definition allocator_traits.hpp:129
decltype(rebind_impl< Allocator >(0)) type
Definition allocator_traits.hpp:130
Definition allocator_traits.hpp:76
Definition allocator_traits.hpp:91
Definition allocator_traits.hpp:97
std::true_type type
Definition allocator_traits.hpp:160
std::false_type type
Definition allocator_traits.hpp:154
Definition allocator_traits.hpp:144
Definition allocator_traits.hpp:88
Definition allocator_traits.hpp:85
#define WPI_AUTO_RETURN(Expr)
Definition utility.hpp:88
#define WPI_AUTO_RETURN_TYPE(Expr, T)
Definition utility.hpp:95
#define WPI_SFINAE(Expr)
Definition utility.hpp:85
#define WPI_MEMORY_UNREACHABLE(Msg)
Definition assert.hpp:48