Blaze 3.9
Loading...
Searching...
No Matches
blaze::AlignedArray< Type, N, Alignment > Class Template Reference

Implementation of a static array with a fixed alignment. More...

#include <AlignedArray.h>

Public Types

using ElementType = Type
 Type of the array elements.
using Pointer = Type*
 Pointer to a non-constant array element.
using ConstPointer = const Type*
 Pointer to a constant array element.
using Reference = Type&
 Reference to a non-constant array element.
using ConstReference = const Type&
 Reference to a constant array element.
using Iterator = Type*
 Iterator over non-constant elements.
using ConstIterator = const Type*
 Iterator over constant elements.

Public Member Functions

template<typename T, size_t M>
constexpr AlignedArray< Type, N, Alignment > & operator= (const T(&array)[M])
 Assignment to all array elements from the given static array.
template<typename T, size_t M>
constexpr AlignedArray< Type, N, Alignment > & operator= (const std::array< T, M > &array)
 Assignment to all array elements from the given std::array.
template<typename T, size_t M>
constexpr AlignedArray< Type, N, Alignment > & operator= (const AlignedArray< T, M > &array)
 Assignment to all array elements from another aligned array.
Destructor
Conversion operators
constexpr operator Pointer () noexcept
 Conversion operator to a pointer.
constexpr operator ConstPointer () const noexcept
 Conversion operator to a pointer-to-const.
Data access functions
constexpr Reference operator[] (size_t index) noexcept
 Subscript operator for the direct access to the array elements.
constexpr ConstReference operator[] (size_t index) const noexcept
 Subscript operator for the direct access to the array elements.
Reference at (size_t index)
 Checked access to the array elements.
ConstReference at (size_t index) const
 Checked access to the array elements.
constexpr Pointer data () noexcept
 Low-level data access to the array elements.
constexpr ConstPointer data () const noexcept
 Low-level data access to the array elements.
constexpr Iterator begin () noexcept
 Returns an iterator to the first element of the aligned array.
constexpr ConstIterator begin () const noexcept
 Returns an iterator to the first element of the aligned array.
constexpr ConstIterator cbegin () const noexcept
 Returns an iterator to the first element of the aligned array.
constexpr Iterator end () noexcept
 Returns an iterator just past the last element of the aligned array.
constexpr ConstIterator end () const noexcept
 Returns an iterator just past the last element of the aligned array.
constexpr ConstIterator cend () const noexcept
 Returns an iterator just past the last element of the aligned array.
Assignment operators
AlignedArray & operator= (const AlignedArray &)=default
AlignedArray & operator= (AlignedArray &&)=default
template<typename T, size_t M>
constexpr AlignedArray & operator= (const T(&array)[M])
template<typename T, size_t M>
constexpr AlignedArray & operator= (const std::array< T, M > &array)
template<typename T, size_t M>
constexpr AlignedArray & operator= (const AlignedArray< T, M > &array)
Utility functions
constexpr size_t size () const noexcept
 Returns the current size/dimension of the aligned array.

Constructors

 AlignedArray (const AlignedArray &)=default
 AlignedArray (AlignedArray &&)=default
template<typename... Ts>
constexpr AlignedArray (const Ts &... args)
 Initialization constructor for AlignedArray.
template<typename T, size_t M>
constexpr AlignedArray (const T(&array)[M])
 Initialization of all aligned array elements from the given static array.
template<typename T, size_t M>
constexpr AlignedArray (const std::array< T, M > &array)
 Initialization of all aligned array elements from the given std::array.
template<typename T, size_t M>
constexpr AlignedArray (const AlignedArray< T, M > &array)
 Initialization of all aligned array elements from another aligned array.
template<typename T, size_t... Is>
constexpr AlignedArray (const T &array, std::index_sequence< Is... >)
 Initialization of all aligned array elements from the given array.

Detailed Description

template<typename Type, size_t N, size_t Alignment = AlignmentOf_v<Type>>
class blaze::AlignedArray< Type, N, Alignment >

Implementation of a static array with a fixed alignment.

The AlignedArray class template represents a static array with a guaranteed, fixed alignment. The type of the array elements, the number of elements and the alignment of the array can be specified via the three template parameters:

template< typename Type, size_t N, size_t Alignment >
class AlignedArray;

The alignment of the array, which must be a power of two (i.e. 1, 2, 4, 8, ...), can either be specified explicitly via the template parameter Alignment or it is evaluated automatically based on the alignment requirements of the given data type Type. In the latter case, if T is a built-in, vectorizable data type, AlignedArray enforces an alignment of 16 or 32 bytes, depending on the active SSE/AVX level. In all other cases, no specific alignment is enforced.

AlignedArray can be used exactly like any built-in static array. It is possible to access the individual element via the subscript operator and the array can be used wherever a pointer is expected:

void func( const int* );
array[10] = 2; // Accessing and assigning the 10th array element
func( array ); // Passing the aligned array to a function expecting a pointer
blaze::AlignedArray<int,3UL> array2{ 1, 2, 3 }; // Directly initialized array
blaze::AlignedArray<int,3UL> array3( 1, 2, 3 ); // Same effect as above
Implementation of a static array with a fixed alignment.
Definition AlignedArray.h:101

Constructor & Destructor Documentation

◆ AlignedArray() [1/5]

template<typename Type, size_t N, size_t Alignment>
template<typename... Ts>
blaze::AlignedArray< Type, N, Alignment >::AlignedArray ( const Ts &... args)
constexpr

Initialization constructor for AlignedArray.

Parameters
argsPack of initialization values.

◆ AlignedArray() [2/5]

template<typename Type, size_t N, size_t Alignment>
template<typename T, size_t M>
blaze::AlignedArray< Type, N, Alignment >::AlignedArray ( const T(&) array[M])
constexpr

Initialization of all aligned array elements from the given static array.

Parameters
arrayThe given static array for the initialization.

The aligned array is initialized with the values from the given static array. Missing values are initialized with default values.

◆ AlignedArray() [3/5]

template<typename Type, size_t N, size_t Alignment>
template<typename T, size_t M>
blaze::AlignedArray< Type, N, Alignment >::AlignedArray ( const std::array< T, M > & array)
constexpr

Initialization of all aligned array elements from the given std::array.

Parameters
arrayThe given std::array for the initialization.

The aligned array is initialized with the values from the given std::array. Missing values are initialized with default values.

◆ AlignedArray() [4/5]

template<typename Type, size_t N, size_t Alignment>
template<typename T, size_t M>
blaze::AlignedArray< Type, N, Alignment >::AlignedArray ( const AlignedArray< T, M > & array)
constexpr

Initialization of all aligned array elements from another aligned array.

Parameters
arrayThe given aligned array for the initialization.

The aligned array is initialized with the values from the another aligned array. Missing values are initialized with default values.

◆ AlignedArray() [5/5]

template<typename Type, size_t N, size_t Alignment>
template<typename T, size_t... Is>
blaze::AlignedArray< Type, N, Alignment >::AlignedArray ( const T & array,
std::index_sequence< Is... >  )
constexprprivate

Initialization of all aligned array elements from the given array.

Parameters
arrayThe given array for the initialization.

The aligned array is initialized with the values from the given array. Missing values are initialized with default values.

Member Function Documentation

◆ at() [1/2]

template<typename Type, size_t N, size_t Alignment>
AlignedArray< Type, N, Alignment >::Reference blaze::AlignedArray< Type, N, Alignment >::at ( size_t index)
inline

Checked access to the array elements.

Parameters
indexAccess index. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.
Exceptions
std::out_of_rangeInvalid array access index.

In contrast to the subscript operator this function always performs a check of the given access index.

◆ at() [2/2]

template<typename Type, size_t N, size_t Alignment>
AlignedArray< Type, N, Alignment >::ConstReference blaze::AlignedArray< Type, N, Alignment >::at ( size_t index) const
inline

Checked access to the array elements.

Parameters
indexAccess index. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.
Exceptions
std::out_of_rangeInvalid array access index.

In contrast to the subscript operator this function always performs a check of the given access index.

◆ begin() [1/2]

template<typename Type, size_t N, size_t Alignment>
AlignedArray< Type, N, Alignment >::ConstIterator blaze::AlignedArray< Type, N, Alignment >::begin ( ) const
constexprnoexcept

Returns an iterator to the first element of the aligned array.

Returns
Iterator to the first element of the aligned array.

◆ begin() [2/2]

template<typename Type, size_t N, size_t Alignment>
AlignedArray< Type, N, Alignment >::Iterator blaze::AlignedArray< Type, N, Alignment >::begin ( )
constexprnoexcept

Returns an iterator to the first element of the aligned array.

Returns
Iterator to the first element of the aligned array.

◆ cbegin()

template<typename Type, size_t N, size_t Alignment>
AlignedArray< Type, N, Alignment >::ConstIterator blaze::AlignedArray< Type, N, Alignment >::cbegin ( ) const
constexprnoexcept

Returns an iterator to the first element of the aligned array.

Returns
Iterator to the first element of the aligned array.

◆ cend()

template<typename Type, size_t N, size_t Alignment>
AlignedArray< Type, N, Alignment >::ConstIterator blaze::AlignedArray< Type, N, Alignment >::cend ( ) const
constexprnoexcept

Returns an iterator just past the last element of the aligned array.

Returns
Iterator just past the last element of the aligned array.

◆ data() [1/2]

template<typename Type, size_t N, size_t Alignment>
AlignedArray< Type, N, Alignment >::ConstPointer blaze::AlignedArray< Type, N, Alignment >::data ( ) const
constexprnoexcept

Low-level data access to the array elements.

Returns
Pointer to the internal element storage.

This function returns a pointer to the internal storage of the aligned array.

◆ data() [2/2]

template<typename Type, size_t N, size_t Alignment>
AlignedArray< Type, N, Alignment >::Pointer blaze::AlignedArray< Type, N, Alignment >::data ( )
constexprnoexcept

Low-level data access to the array elements.

Returns
Pointer to the internal element storage.

This function returns a pointer to the internal storage of the aligned array.

◆ end() [1/2]

template<typename Type, size_t N, size_t Alignment>
AlignedArray< Type, N, Alignment >::ConstIterator blaze::AlignedArray< Type, N, Alignment >::end ( ) const
constexprnoexcept

Returns an iterator just past the last element of the aligned array.

Returns
Iterator just past the last element of the aligned array.

◆ end() [2/2]

template<typename Type, size_t N, size_t Alignment>
AlignedArray< Type, N, Alignment >::Iterator blaze::AlignedArray< Type, N, Alignment >::end ( )
constexprnoexcept

Returns an iterator just past the last element of the aligned array.

Returns
Iterator just past the last element of the aligned array.

◆ operator ConstPointer()

template<typename Type, size_t N, size_t Alignment>
blaze::AlignedArray< Type, N, Alignment >::operator ConstPointer ( ) const
constexprnoexcept

Conversion operator to a pointer-to-const.

Returns
The raw pointer of the aligned array.

◆ operator Pointer()

template<typename Type, size_t N, size_t Alignment>
blaze::AlignedArray< Type, N, Alignment >::operator Pointer ( )
constexprnoexcept

Conversion operator to a pointer.

Returns
The raw pointer of the aligned array.

◆ operator=() [1/3]

template<typename Type, size_t N, size_t Alignment = AlignmentOf_v<Type>>
template<typename T, size_t M>
AlignedArray< Type, N, Alignment > & blaze::AlignedArray< Type, N, Alignment >::operator= ( const AlignedArray< T, M > & array)
constexpr

Assignment to all array elements from another aligned array.

Parameters
arrayThe given aligned array for the assignment.
Returns
Reference to the assigned array.

The elements of the aligned array are assigned the values from another aligned array. Missing values are assigned default values.

◆ operator=() [2/3]

template<typename Type, size_t N, size_t Alignment = AlignmentOf_v<Type>>
template<typename T, size_t M>
AlignedArray< Type, N, Alignment > & blaze::AlignedArray< Type, N, Alignment >::operator= ( const std::array< T, M > & array)
constexpr

Assignment to all array elements from the given std::array.

Parameters
arrayThe given std::array for the assignment.
Returns
Reference to the assigned array.

The elements of the aligned array are assigned the values from the given std::array. Missing values are assigned default values.

◆ operator=() [3/3]

template<typename Type, size_t N, size_t Alignment = AlignmentOf_v<Type>>
template<typename T, size_t M>
AlignedArray< Type, N, Alignment > & blaze::AlignedArray< Type, N, Alignment >::operator= ( const T(&) array[M])
constexpr

Assignment to all array elements from the given static array.

Parameters
arrayThe given static array for the assignment.
Returns
Reference to the assigned array.

The elements of the aligned array are assigned the values from the given static array. Missing values are assigned default values.

◆ operator[]() [1/2]

template<typename Type, size_t N, size_t Alignment>
AlignedArray< Type, N, Alignment >::ConstReference blaze::AlignedArray< Type, N, Alignment >::operator[] ( size_t index) const
constexprnoexcept

Subscript operator for the direct access to the array elements.

Parameters
indexAccess index. The index has to be in the range $[0..N-1]$.
Returns
Reference-to-const to the accessed value.
Note
This operator does not perform any kind of index check!

◆ operator[]() [2/2]

template<typename Type, size_t N, size_t Alignment>
AlignedArray< Type, N, Alignment >::Reference blaze::AlignedArray< Type, N, Alignment >::operator[] ( size_t index)
constexprnoexcept

Subscript operator for the direct access to the array elements.

Parameters
indexAccess index. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.
Note
This operator does not perform any kind of index check!

◆ size()

template<typename Type, size_t N, size_t Alignment>
size_t blaze::AlignedArray< Type, N, Alignment >::size ( ) const
constexprnoexcept

Returns the current size/dimension of the aligned array.

Returns
The size of the array.

The documentation for this class was generated from the following file: