28 #ifndef VC_ALLOCATOR_H_
29 #define VC_ALLOCATOR_H_
37 #include "common/macros.h"
50 #define Vc_DECLARE_ALLOCATOR(Type) \
53 template <> class allocator<Type> : public ::Vc::Allocator<Type> \
56 template <typename U> struct rebind { \
57 typedef ::std::allocator<U> other; \
61 const allocator &select_on_container_copy_construction() const { return *this; } \
65 #define Vc_DECLARE_ALLOCATOR(Type) \
68 template <> class allocator<Type> : public ::Vc::Allocator<Type> \
71 template <typename U> struct rebind { \
72 typedef ::std::allocator<U> other; \
78 namespace Vc_VERSIONED_NAMESPACE
132 #ifdef Vc_HAVE_STD_MAX_ALIGN_T
133 NaturalAlignment =
alignof(std::max_align_t),
134 #elif defined(Vc_HAVE_MAX_ALIGN_T)
135 NaturalAlignment =
alignof(::max_align_t),
137 NaturalAlignment =
sizeof(
void *) >
alignof(
long double) ?
sizeof(
void *) :
138 (
alignof(
long double) >
alignof(
long long) ?
alignof(
long double) :
alignof(
long long)),
140 #
if defined Vc_IMPL_AVX
142 #elif defined Vc_IMPL_SSE
147 Alignment =
alignof(T) > SimdAlignment ?
alignof(T) : SimdAlignment,
164 ExtraBytes = Alignment > NaturalAlignment ? Alignment : 0,
165 AlignmentMask = Alignment - 1
168 typedef size_t size_type;
169 typedef ptrdiff_t difference_type;
171 typedef const T* const_pointer;
172 typedef T& reference;
173 typedef const T& const_reference;
174 typedef T value_type;
176 template<
typename U>
struct rebind {
typedef Allocator<U> other; };
182 pointer address(reference x)
const {
return &x; }
183 const_pointer address(const_reference x)
const {
return &x; }
185 pointer allocate(size_type n,
const void* = 0)
187 if (n > this->max_size()) {
188 throw std::bad_alloc();
191 char *p =
static_cast<char *
>(::operator
new(n *
sizeof(T) + ExtraBytes));
192 if (ExtraBytes > 0) {
195 const char *
null = 0;
196 p -= ((p -
null) & AlignmentMask);
197 reinterpret_cast<char **
>(p)[-1] = pp;
199 return reinterpret_cast<pointer
>(p);
202 void deallocate(pointer p, size_type)
204 if (ExtraBytes > 0) {
205 p =
reinterpret_cast<pointer *
>(p)[-1];
207 ::operator
delete(p);
210 size_type max_size()
const throw() {
return size_t(-1) /
sizeof(T); }
214 const Allocator &select_on_container_copy_construction()
const {
return *
this; }
218 void construct(pointer p) { ::new(p) T(); }
221 void construct(pointer p,
const T& val) { ::new(p) T(val); }
222 void destroy(pointer p) { p->~T(); }
224 template<
typename U,
typename... Args>
void construct(U* p, Args&&... args)
226 ::new(p) U(std::forward<Args>(args)...);
228 template<
typename U>
void destroy(U* p) { p->~U(); }
233 template<
typename T>
inline bool operator!=(
const Allocator<T>&,
const Allocator<T>&) {
return false; }
240 template<
typename T,
typename Abi>
241 class allocator<
Vc::Vector<T, Abi> > :
public ::Vc::Allocator<Vc::Vector<T, Abi> >
244 template<
typename U>
struct rebind { typedef ::std::allocator<U> other; };
247 const allocator &select_on_container_copy_construction()
const {
return *
this; }
250 template <
typename T,
typename Abi>
254 template<
typename U>
struct rebind { typedef ::std::allocator<U> other; };
257 const allocator &select_on_container_copy_construction()
const {
return *
this; }
260 template <
typename T, std::
size_t N,
typename V, std::
size_t M>
261 class allocator<
Vc::SimdArray<T, N, V, M>> :
public ::Vc::Allocator<Vc::SimdArray<T, N, V, M>>
264 template<
typename U>
struct rebind { typedef ::std::allocator<U> other; };
267 const allocator &select_on_container_copy_construction()
const {
return *
this; }
270 template <
typename T, std::
size_t N,
typename V, std::
size_t M>
271 class allocator<
Vc::SimdMaskArray<T, N, V, M>> :
public ::Vc::Allocator<Vc::SimdMaskArray<T, N, V, M>>
274 template<
typename U>
struct rebind { typedef ::std::allocator<U> other; };
277 const allocator &select_on_container_copy_construction()
const {
return *
this; }
282 #endif // VC_ALLOCATOR_H_