3 #include "../utility/aligned_malloc.h"
4 #include "../utility/alignment.h"
5 #include "../utility/empty_base.h"
6 #include "../utility/meta.h"
12 #include <type_traits>
16 template<
typename Alloc>
20 static_assert(detail::has_no_value_type_v<Alloc>,
"Building on top of typed allocators is not allowed. Use allocators without a type");
25 template<
typename A = Alloc>
27 noexcept(std::is_nothrow_default_constructible_v<Alloc>) :
34 template<
typename... Args,
35 typename = std::enable_if_t<
36 std::is_constructible_v<Alloc, Args...>>>
38 noexcept(std::is_nothrow_constructible_v<Alloc, Args...>) :
39 m_Alloc(std::forward<Args>(args) ...),
49 noexcept(detail::has_nothrow_equal_v<Alloc>)
51 return m_Alloc == rhs.m_Alloc;
55 noexcept(detail::has_nothrow_not_equal_v<Alloc>)
57 return m_Alloc != rhs.m_Alloc;
60 #pragma region Allocation
63 std::lock_guard<std::mutex> lock(m_Lock);
65 return m_Alloc.allocate(n);
70 std::lock_guard<std::mutex> lock(m_Lock);
72 m_Alloc.deallocate(p, n);
76 #pragma region Construction
77 template<
typename T,
typename... Args>
80 noexcept(detail::has_nothrow_construct_v<Alloc, T*, Args...>)
84 m_Alloc.construct(p, std::forward<Args>(args)...);
88 typename std::enable_if<detail::has_destroy_v<Alloc, T*>,
void>::type
90 noexcept(detail::has_nothrow_destroy_v<Alloc, T*>)
98 #pragma region Utility
99 template<
typename A = Alloc>
100 typename std::enable_if<detail::has_max_size_v<A>,
size_type>::type
104 return m_Alloc.max_size();
107 template<
typename A = Alloc>
108 typename std::enable_if<detail::has_owns_v<A>,
bool>::type
110 noexcept(detail::has_nothrow_owns_v<A>)
112 return m_Alloc.owns(p);
Definition: threaded.h:18
std::enable_if< detail::has_destroy_v< Alloc, T * >, void >::type destroy(T *p) noexcept(detail::has_nothrow_destroy_v< Alloc, T * >)
Definition: threaded.h:89
bool operator!=(const threaded &rhs) const noexcept(detail::has_nothrow_not_equal_v< Alloc >)
Definition: threaded.h:54
threaded(threaded &&)=delete
std::enable_if< detail::has_construct_v< Alloc, T *, Args... >, void >::type construct(T *p, Args &&... args) noexcept(detail::has_nothrow_construct_v< Alloc, T *, Args... >)
Definition: threaded.h:79
const Alloc & get_allocator() const noexcept
Definition: threaded.h:121
bool operator==(const threaded &rhs) const noexcept(detail::has_nothrow_equal_v< Alloc >)
Definition: threaded.h:48
threaded(Args &&... args) noexcept(std::is_nothrow_constructible_v< Alloc, Args... >)
Constructor for forwarding any arguments to the underlying allocator.
Definition: threaded.h:37
Alloc & get_allocator() noexcept
Definition: threaded.h:116
void * allocate(size_t n)
Definition: threaded.h:61
threaded & operator=(const threaded &)=delete
std::enable_if< detail::has_max_size_v< A >, size_type >::type max_size() const noexcept(detail::has_nothrow_max_size_v< A >)
Definition: threaded.h:101
void deallocate(void *p, size_t n)
Definition: threaded.h:68
threaded() noexcept(std::is_nothrow_default_constructible_v< Alloc >)
Definition: threaded.h:26
threaded & operator=(threaded &&)=delete
threaded(const threaded &)=delete
std::enable_if< detail::has_owns_v< A >, bool >::type owns(void *p) const noexcept(detail::has_nothrow_owns_v< A >)
Definition: threaded.h:109
detail::get_size_type_t< Alloc > size_type
Definition: threaded.h:20
#define KTL_EMPTY_BASE
Definition: empty_base.h:6
constexpr bool has_construct_v
Definition: meta.h:41
typename get_size_type< Alloc, void >::type get_size_type_t
Definition: meta.h:31
constexpr bool has_nothrow_max_size_v
Definition: meta.h:122
Definition: cascading.h:15