30 #ifndef BIT_MEMORY_CONCEPTS_BLOCKALLOCATOR_HPP 31 #define BIT_MEMORY_CONCEPTS_BLOCKALLOCATOR_HPP 33 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 35 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 37 #include "detail/identity.hpp" 38 #include "detail/void_t.hpp" 40 #include "../utilities/allocator_info.hpp" 41 #include "../utilities/memory_block.hpp" 43 #include <type_traits> 96 #if __cplusplus >= 202000L 100 concept BlockAllocator = requires( A a, memory_block block )
102 { block = a.allocate_block() } -> memory_block;
103 { a.deallocate_block( block ) } -> void;
104 { a.next_block_size() } -> std::size_t;
110 template<
typename T,
typename =
void>
111 struct block_allocator_has_allocate_block_impl : std::false_type{};
114 struct block_allocator_has_allocate_block_impl<T,void_t<
115 decltype(
std::declval<memory_block&>() = std::declval<T&>().allocate_block() )
116 >> : std::true_type{};
120 template<
typename T,
typename =
void>
121 struct block_allocator_has_deallocate_block_impl : std::false_type{};
124 struct block_allocator_has_deallocate_block_impl<T,void_t<
125 decltype(
std::declval<T&>().deallocate_block( std::declval<memory_block&>() ) )
126 >> : std::true_type{};
130 template<
typename T,
typename =
void>
131 struct block_allocator_has_default_block_alignment_impl : std::false_type{};
134 struct block_allocator_has_default_block_alignment_impl<T,void_t<
135 decltype(T::default_block_alignment)>
136 > : std::true_type{};
140 template<
typename T,
typename =
void>
141 struct block_allocator_has_next_block_size_impl : std::false_type{};
144 struct block_allocator_has_next_block_size_impl<T,void_t<
145 decltype(
std::declval<std::size_t&>() = std::declval<const T&>().next_block_size())>
146 > : std::true_type{};
150 template<
typename T,
typename =
void>
151 struct block_allocator_has_next_block_alignment_impl : std::false_type{};
154 struct block_allocator_has_next_block_alignment_impl<T,void_t<
155 decltype(
std::declval<std::size_t&>() = std::declval<const T&>().next_block_alignment())>
156 > : std::true_type{};
160 template<
typename T,
typename =
void>
161 struct block_allocator_has_info_impl : std::false_type{};
164 struct block_allocator_has_info_impl<T,
165 void_t<decltype(
std::declval<allocator_info>() = std::declval<const T&>().info() )>
166 > : std::true_type{};
177 : detail::block_allocator_has_default_block_alignment_impl<T>{};
184 constexpr std::size_t block_allocator_default_block_alignment_v
196 : detail::block_allocator_has_next_block_size_impl<T>{};
203 constexpr std::size_t block_allocator_has_next_block_size_v
215 : detail::block_allocator_has_next_block_alignment_impl<T>{};
222 constexpr std::size_t block_allocator_has_next_block_alignment_v
234 : detail::block_allocator_has_info_impl<T>{};
241 constexpr
bool block_allocator_has_info_v
254 detail::block_allocator_has_allocate_block_impl<T>::value &&
255 detail::block_allocator_has_deallocate_block_impl<T>::value &&
256 detail::block_allocator_has_next_block_size_impl<T>::value
Type-trait to determine whether T defines an 'info' function.
Type-trait to determine whether T defines 'block_size'.
Type-trait to determine whether T defines 'default_block_alignment'.
Type-trait to determine whether T defines 'block_size'.
Type-trait to determine whether T satisfies the minimum requirements to be a BlockAllocator.