21#ifndef EWOMS_ALIGNED_ALLOCATOR_HH
22#define EWOMS_ALIGNED_ALLOCATOR_HH
32constexpr inline bool is_alignment(std::size_t value)
noexcept
34 return (value > 0) && ((value & (value - 1)) == 0);
37template<std::
size_t N>
39 : std::integral_constant<bool, (N > 0) && ((N & (N - 1)) == 0)>
42template<std::
size_t A, std::
size_t B>
44 : std::integral_constant<std::size_t, (A < B) ? A : B>
56 : min_size<sizeof(T), sizeof(offset_object<T>) - sizeof(T)>::type
59template<std::size_t A, std::size_t B>
61 : std::integral_constant<std::size_t,(A > B) ? A : B>
66 : std::integral_constant<std::size_t, ~static_cast<std::size_t>(0) / sizeof(T)>
72inline void* aligned_alloc(std::size_t alignment,
73 std::size_t size)
noexcept
75 assert(detail::is_alignment(alignment));
76 if (alignment <
sizeof(
void*)) {
77 alignment =
sizeof(
void*);
80 if (::posix_memalign(&p, alignment, size) != 0) {
86inline void aligned_free(
void* ptr)
93template<
class T, std::
size_t Alignment>
100 using const_pointer =
const T*;
101 using void_pointer =
void*;
102 using const_void_pointer =
const void*;
103 using size_type = std::size_t;
104 using difference_type = std::ptrdiff_t;
105 using reference = T&;
106 using const_reference =
const T&;
122 Alignment>&) noexcept {
125 pointer address(reference value)
const
127 return detail::addressof(value);
130 const_pointer address(const_reference value)
const
132 return detail::addressof(value);
135 pointer allocate(size_type size,
136 const_void_pointer = 0) {
137 void* p = aligned_alloc(MaxAlign::value,
139 if (!p && size > 0) {
140 throw std::bad_alloc();
142 return static_cast<T*
>(p);
145 void deallocate(pointer ptr, size_type) {
149 constexpr size_type max_size() const
151 return detail::max_count_of<T>::value;
154 template<
class U,
class... Args>
155 void construct(U* ptr, Args&&... args) {
157 ::new(p) U(std::forward<Args>(args)...);
161 void construct(U* ptr) {
167 void destroy(U* ptr) {
173template<std::
size_t Alignment>
176 "The specified alignment is not a power of two!");
179 using value_type = void;
180 using pointer =
void*;
181 using const_pointer =
const void*;
189template<
class T1,
class T2, std::
size_t Alignment>
192 Alignment>&) noexcept
197template<
class T1,
class T2, std::
size_t Alignment>
198inline bool operator!=(
const aligned_allocator<T1,
199 Alignment>&,
const aligned_allocator<T2,
200 Alignment>&) noexcept
Definition alignedallocator.hh:94
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
Definition alignedallocator.hh:113
Definition alignedallocator.hh:184
Definition alignedallocator.hh:40
Definition alignedallocator.hh:62
Definition alignedallocator.hh:67
Definition alignedallocator.hh:45