diff options
author | Gael Guennebaud <g.gael@free.fr> | 2014-03-19 13:28:50 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2014-03-19 13:28:50 +0100 |
commit | 2a564695f0e9391eb3a0125bd5731c17aabdb680 (patch) | |
tree | e81b968a7f446d4b5181c858af3ea8146f42e721 /Eigen/src/Core/util/Memory.h | |
parent | 3e42b775ead02a2b389840b1b8fd7c28121fb387 (diff) |
Simpler and hopefully more future-proof fix for bug #503 (aligned_allocator with c++11)
Diffstat (limited to 'Eigen/src/Core/util/Memory.h')
-rw-r--r-- | Eigen/src/Core/util/Memory.h | 112 |
1 files changed, 28 insertions, 84 deletions
diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h index 286e963d2..0f8ab065a 100644 --- a/Eigen/src/Core/util/Memory.h +++ b/Eigen/src/Core/util/Memory.h @@ -700,98 +700,42 @@ template<typename T> class aligned_stack_memory_handler * \sa \ref TopicStlContainers. */ template<class T> -class aligned_allocator +class aligned_allocator : public std::allocator<T> { public: - typedef size_t size_type; - typedef std::ptrdiff_t difference_type; - typedef T* pointer; - typedef const T* const_pointer; - typedef T& reference; - typedef const T& const_reference; - typedef T value_type; - - template<class U> - struct rebind - { - typedef aligned_allocator<U> other; - }; - - pointer address( reference value ) const - { - return &value; - } - - const_pointer address( const_reference value ) const - { - return &value; - } - - aligned_allocator() - { - } - - aligned_allocator( const aligned_allocator& ) - { - } - - template<class U> - aligned_allocator( const aligned_allocator<U>& ) - { - } - - ~aligned_allocator() - { - } - - size_type max_size() const - { - return (std::numeric_limits<size_type>::max)(); - } - - pointer allocate( size_type num, const void* hint = 0 ) - { - EIGEN_UNUSED_VARIABLE(hint); - internal::check_size_for_overflow<T>(num); - return static_cast<pointer>( internal::aligned_malloc( num * sizeof(T) ) ); - } - - void construct( pointer p, const T& value ) - { - ::new( p ) T( value ); - } + typedef size_t size_type; + typedef std::ptrdiff_t difference_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + typedef T value_type; + + template<class U> + struct rebind + { + typedef aligned_allocator<U> other; + }; -#if (__cplusplus >= 201103L) - template <typename U, typename... Args> - void construct( U* u, Args&&... args) - { - ::new( static_cast<void*>(u) ) U( std::forward<Args>( args )... ); - } -#endif + aligned_allocator() : std::allocator<T>() {} - void destroy( pointer p ) - { - p->~T(); - } + aligned_allocator(const aligned_allocator& other) : std::allocator<T>(other) {} -#if (__cplusplus >= 201103L) - template <typename U> - void destroy( U* u ) - { - u->~U(); - } -#endif + template<class U> + aligned_allocator(const aligned_allocator<U>& other) : std::allocator<T>(other) {} - void deallocate( pointer p, size_type /*num*/ ) - { - internal::aligned_free( p ); - } + ~aligned_allocator() {} - bool operator!=(const aligned_allocator<T>& ) const - { return false; } + pointer allocate(size_type num, const void* /*hint*/ = 0) + { + internal::check_size_for_overflow<T>(num); + return static_cast<pointer>( internal::aligned_malloc(num * sizeof(T)) ); + } - bool operator==(const aligned_allocator<T>& ) const - { return true; } + void deallocate(pointer p, size_type /*num*/) + { + internal::aligned_free(p); + } }; //---------- Cache sizes ---------- |