6 #ifndef LAPACK_NO_CONSTRUCT_ALLOCATOR_HH
7 #define LAPACK_NO_CONSTRUCT_ALLOCATOR_HH
13 struct NoConstructAllocator
17 NoConstructAllocator () =
default;
25 template <
typename... Args>
26 void construct( T* ptr, Args&& ... args ) { }
29 void destroy( T* ptr ) { }
31 T* allocate(std::size_t n)
33 if (n > std::numeric_limits<std::size_t>::max() /
sizeof(T))
34 throw std::bad_array_new_length();
36 void* memPtr =
nullptr;
37 #if defined( _WIN32 ) || defined( _WIN64 )
38 memPtr = _aligned_malloc( n*
sizeof(T, 64) );
39 if (memPtr !=
nullptr) {
40 auto p =
static_cast<T*
>(memPtr);
44 int err = posix_memalign( &memPtr, 64, n*
sizeof(T) );
46 auto p =
static_cast<T*
>(memPtr);
51 throw std::bad_alloc();
54 void deallocate(T* p, std::size_t n) noexcept
56 #if defined( _WIN32 ) || defined( _WIN64 )
64 template <
class T,
class U>
65 bool operator==(
const NoConstructAllocator <T>&,
const NoConstructAllocator <U>&)
70 template <
class T,
class U>
71 bool operator!=(
const NoConstructAllocator <T>&,
const NoConstructAllocator <U>&)
77 using vector = std::vector< T, NoConstructAllocator<T> >;
81 #endif // LAPACK_NO_CONSTRUCT_ALLOCATOR_HH