21#ifndef EWOMS_ALIGNED_ALLOCATOR_HH
22#define EWOMS_ALIGNED_ALLOCATOR_HH
34constexpr inline bool is_alignment(std::size_t value)
noexcept
36 return (value > 0) && ((value & (value - 1)) == 0);
39template<std::
size_t N>
41 : std::integral_constant<bool, (N > 0) && ((N & (N - 1)) == 0)>
44template<std::
size_t A, std::
size_t B>
46 : std::integral_constant<std::size_t, (A < B) ? A : B>
58 : min_size<sizeof(T), sizeof(offset_object<T>) - sizeof(T)>::type
61template<std::size_t A, std::size_t B>
63 : std::integral_constant<std::size_t,(A > B) ? A : B>
68 : std::integral_constant<std::size_t, ~static_cast<std::size_t>(0) / sizeof(T)>
75inline void* aligned_alloc(std::size_t alignment,
76 std::size_t size)
noexcept
78 assert(detail::is_alignment(alignment));
79 if (alignment <
sizeof(
void*)) {
80 alignment =
sizeof(
void*);
83 if (::posix_memalign(&p, alignment, size) != 0) {
89inline void aligned_free(
void* ptr)
95template<
class T, std::
size_t Alignment>
96class aligned_allocator
101 using value_type = T;
103 using const_pointer =
const T*;
104 using void_pointer =
void*;
105 using const_void_pointer =
const void*;
106 using size_type = std::size_t;
107 using difference_type = std::ptrdiff_t;
108 using reference = T&;
109 using const_reference =
const T&;
118 using other = aligned_allocator<U, Alignment>;
121 aligned_allocator() noexcept = default;
124 aligned_allocator(const aligned_allocator<U,
125 Alignment>&) noexcept
128 pointer address(reference value)
const noexcept
130 return detail::addressof(value);
133 const_pointer address(const_reference value)
const noexcept
135 return detail::addressof(value);
138 pointer allocate(size_type size,
139 const_void_pointer = 0)
141 void* p = aligned_alloc(MaxAlign::value,
143 if (!p && size > 0) {
144 throw std::bad_alloc();
146 return static_cast<T*
>(p);
149 void deallocate(pointer ptr, size_type)
154 constexpr size_type max_size() const noexcept
156 return detail::max_count_of<T>::value;
159 template<
class U,
class... Args>
160 void construct(U* ptr, Args&&... args)
163 ::new(p) U(std::forward<Args>(args)...);
167 void construct(U* ptr)
181template<std::
size_t Alignment>
182class aligned_allocator<void, Alignment>
185 "The specified alignment is not a power of two!");
188 using value_type = void;
189 using pointer =
void*;
190 using const_pointer =
const void*;
195 using other = aligned_allocator<U, Alignment>;
199template<
class T1,
class T2, std::
size_t Alignment>
202 Alignment>&) noexcept
207template<
class T1,
class T2, std::
size_t Alignment>
208inline bool operator!=(
const aligned_allocator<T1,
209 Alignment>&,
const aligned_allocator<T2,
210 Alignment>&) noexcept
Definition alignedallocator.hh:97
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Definition alignedallocator.hh:117
Definition alignedallocator.hh:194
Definition alignedallocator.hh:42
Definition alignedallocator.hh:64
Definition alignedallocator.hh:69
Definition alignedallocator.hh:47