Nektar++
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
tinysimd::aligned_allocator< T, Alignment > Class Template Reference

#include <allocator.hpp>

Classes

struct  rebind
 

Public Types

using value_type = T
 
using pointer = T *
 
using const_pointer = const T *
 
using reference = T &
 
using const_reference = const T &
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using propagate_on_container_move_assignment = std::true_type
 
using is_always_equal = std::true_type
 

Public Member Functions

 aligned_allocator () noexcept=default
 
template<typename U >
 aligned_allocator (const aligned_allocator< U, Alignment > &) noexcept
 
T * allocate (size_type n)
 
void deallocate (T *p, size_type) noexcept
 
constexpr size_type max_size () const noexcept
 
template<typename U , typename... Args>
void construct (U *p, Args &&...args)
 
template<typename U >
void destroy (U *p)
 

Static Public Attributes

static constexpr std::size_t alignment = std::max(Alignment, alignof(T))
 

Detailed Description

template<typename T, std::size_t Alignment>
class tinysimd::aligned_allocator< T, Alignment >

Definition at line 50 of file allocator.hpp.

Member Typedef Documentation

◆ const_pointer

template<typename T , std::size_t Alignment>
using tinysimd::aligned_allocator< T, Alignment >::const_pointer = const T *

Definition at line 55 of file allocator.hpp.

◆ const_reference

template<typename T , std::size_t Alignment>
using tinysimd::aligned_allocator< T, Alignment >::const_reference = const T &

Definition at line 57 of file allocator.hpp.

◆ difference_type

template<typename T , std::size_t Alignment>
using tinysimd::aligned_allocator< T, Alignment >::difference_type = std::ptrdiff_t

Definition at line 59 of file allocator.hpp.

◆ is_always_equal

template<typename T , std::size_t Alignment>
using tinysimd::aligned_allocator< T, Alignment >::is_always_equal = std::true_type

Definition at line 62 of file allocator.hpp.

◆ pointer

template<typename T , std::size_t Alignment>
using tinysimd::aligned_allocator< T, Alignment >::pointer = T *

Definition at line 54 of file allocator.hpp.

◆ propagate_on_container_move_assignment

template<typename T , std::size_t Alignment>
using tinysimd::aligned_allocator< T, Alignment >::propagate_on_container_move_assignment = std::true_type

Definition at line 61 of file allocator.hpp.

◆ reference

template<typename T , std::size_t Alignment>
using tinysimd::aligned_allocator< T, Alignment >::reference = T &

Definition at line 56 of file allocator.hpp.

◆ size_type

template<typename T , std::size_t Alignment>
using tinysimd::aligned_allocator< T, Alignment >::size_type = std::size_t

Definition at line 58 of file allocator.hpp.

◆ value_type

template<typename T , std::size_t Alignment>
using tinysimd::aligned_allocator< T, Alignment >::value_type = T

Definition at line 53 of file allocator.hpp.

Constructor & Destructor Documentation

◆ aligned_allocator() [1/2]

template<typename T , std::size_t Alignment>
tinysimd::aligned_allocator< T, Alignment >::aligned_allocator ( )
defaultnoexcept

◆ aligned_allocator() [2/2]

template<typename T , std::size_t Alignment>
template<typename U >
tinysimd::aligned_allocator< T, Alignment >::aligned_allocator ( const aligned_allocator< U, Alignment > &  )
inlinenoexcept

Definition at line 77 of file allocator.hpp.

78 {
79 }

Member Function Documentation

◆ allocate()

template<typename T , std::size_t Alignment>
T * tinysimd::aligned_allocator< T, Alignment >::allocate ( size_type  n)
inline

Definition at line 81 of file allocator.hpp.

82 {
83 if (n > max_size())
84 {
85 throw std::bad_array_new_length();
86 }
87 return static_cast<T *>(
88 ::operator new(n * sizeof(T), std::align_val_t{alignment}));
89 }
constexpr size_type max_size() const noexcept
Definition allocator.hpp:99
static constexpr std::size_t alignment
Definition allocator.hpp:64

References tinysimd::aligned_allocator< T, Alignment >::alignment, and tinysimd::aligned_allocator< T, Alignment >::max_size().

◆ construct()

template<typename T , std::size_t Alignment>
template<typename U , typename... Args>
void tinysimd::aligned_allocator< T, Alignment >::construct ( U *  p,
Args &&...  args 
)
inline

Definition at line 111 of file allocator.hpp.

112 {
113 ::new (static_cast<void *>(p)) U(std::forward<Args>(args)...);
114 }

◆ deallocate()

template<typename T , std::size_t Alignment>
void tinysimd::aligned_allocator< T, Alignment >::deallocate ( T *  p,
size_type   
)
inlinenoexcept

Definition at line 91 of file allocator.hpp.

92 {
93 if (p != nullptr)
94 {
95 ::operator delete(p, std::align_val_t{alignment});
96 }
97 }
std::vector< double > p(NPUPPER)

References tinysimd::aligned_allocator< T, Alignment >::alignment.

◆ destroy()

template<typename T , std::size_t Alignment>
template<typename U >
void tinysimd::aligned_allocator< T, Alignment >::destroy ( U *  p)
inline

Definition at line 119 of file allocator.hpp.

120 {
121 p->~U();
122 }

◆ max_size()

template<typename T , std::size_t Alignment>
constexpr size_type tinysimd::aligned_allocator< T, Alignment >::max_size ( ) const
inlineconstexprnoexcept

Definition at line 99 of file allocator.hpp.

100 {
101 return std::numeric_limits<size_type>::max() / sizeof(T);
102 }

Referenced by tinysimd::aligned_allocator< T, Alignment >::allocate().

Member Data Documentation

◆ alignment

template<typename T , std::size_t Alignment>
constexpr std::size_t tinysimd::aligned_allocator< T, Alignment >::alignment = std::max(Alignment, alignof(T))
staticconstexpr