tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
allocator_traits.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_MEMORY_ALLOCATOR_TRAITS_HPP
4#define TETL_MEMORY_ALLOCATOR_TRAITS_HPP
5
8
9namespace etl {
10
11namespace detail {
12
13template <typename Alloc>
14struct allocator_traits_pointer {
15 using type = typename Alloc::value_type*;
16};
17
18template <typename Alloc>
19 requires requires { typename Alloc::pointer; }
20struct allocator_traits_pointer<Alloc> {
21 using type = typename Alloc::pointer;
22};
23
24template <typename Alloc>
25struct allocator_traits_const_pointer {
26 using pointer = typename allocator_traits_pointer<Alloc>::type;
27 using type = typename etl::pointer_traits<pointer>::template rebind<typename Alloc::value_type const>;
28};
29
30template <typename Alloc>
31 requires requires { typename Alloc::const_pointer; }
32struct allocator_traits_const_pointer<Alloc> {
33 using type = typename Alloc::const_pointer;
34};
35
36template <typename Alloc>
37struct allocator_traits_void_pointer {
38 using pointer = typename allocator_traits_pointer<Alloc>::type;
39 using type = typename etl::pointer_traits<pointer>::template rebind<void>;
40};
41
42template <typename Alloc>
43 requires requires { typename Alloc::void_pointer; }
44struct allocator_traits_void_pointer<Alloc> {
45 using type = typename Alloc::void_pointer;
46};
47
48template <typename Alloc>
49struct allocator_traits_const_void_pointer {
50 using pointer = typename allocator_traits_pointer<Alloc>::type;
51 using type = typename etl::pointer_traits<pointer>::template rebind<void const>;
52};
53
54template <typename Alloc>
55 requires requires { typename Alloc::const_void_pointer; }
56struct allocator_traits_const_void_pointer<Alloc> {
57 using type = typename Alloc::const_void_pointer;
58};
59
60template <typename Alloc>
61struct allocator_traits_difference_type {
62 using pointer = typename allocator_traits_pointer<Alloc>::type;
64};
65
66template <typename Alloc>
67 requires requires { typename Alloc::difference_type; }
68struct allocator_traits_difference_type<Alloc> {
69 using type = typename Alloc::difference_type;
70};
71
72template <typename Alloc>
73struct allocator_traits_size_type {
74 using difference_type = typename allocator_traits_difference_type<Alloc>::type;
76};
77
78template <typename Alloc>
79 requires requires { typename Alloc::size_type; }
80struct allocator_traits_size_type<Alloc> {
81 using type = typename Alloc::size_type;
82};
83
84} // namespace detail
85
86template <typename Alloc>
88 using allocator_type = Alloc;
89 using value_type = typename Alloc::value_type;
90 using pointer = typename detail::allocator_traits_pointer<Alloc>::type;
91 using const_pointer = typename detail::allocator_traits_const_pointer<Alloc>::type;
92 using void_pointer = typename detail::allocator_traits_void_pointer<Alloc>::type;
93 using const_void_pointer = typename detail::allocator_traits_const_void_pointer<Alloc>::type;
94 using difference_type = typename detail::allocator_traits_difference_type<Alloc>::type;
95 using size_type = typename detail::allocator_traits_size_type<Alloc>::type;
96
97 [[nodiscard]] static constexpr auto allocate(Alloc& a, size_type n) { return a.allocate(n); }
98
99 static constexpr void deallocate(Alloc& a, pointer p, size_type n) { a.deallocate(p, n); }
100};
101
102} // namespace etl
103
104#endif // TETL_MEMORY_ALLOCATOR_TRAITS_HPP
Definition adjacent_find.hpp:8
typename make_unsigned< T >::type make_unsigned_t
Definition make_unsigned.hpp:75
Definition allocator_traits.hpp:87
typename detail::allocator_traits_const_pointer< Alloc >::type const_pointer
Definition allocator_traits.hpp:91
typename detail::allocator_traits_const_void_pointer< Alloc >::type const_void_pointer
Definition allocator_traits.hpp:93
typename Alloc::value_type value_type
Definition allocator_traits.hpp:89
typename detail::allocator_traits_void_pointer< Alloc >::type void_pointer
Definition allocator_traits.hpp:92
static constexpr auto allocate(Alloc &a, size_type n)
Definition allocator_traits.hpp:97
static constexpr void deallocate(Alloc &a, pointer p, size_type n)
Definition allocator_traits.hpp:99
Alloc allocator_type
Definition allocator_traits.hpp:88
typename detail::allocator_traits_size_type< Alloc >::type size_type
Definition allocator_traits.hpp:95
typename detail::allocator_traits_pointer< Alloc >::type pointer
Definition allocator_traits.hpp:90
typename detail::allocator_traits_difference_type< Alloc >::type difference_type
Definition allocator_traits.hpp:94
typename Ptr::difference_type difference_type
Definition pointer_traits.hpp:20