Blaze  3.6
AlignedArray.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_UTIL_ALIGNEDARRAY_H_
36 #define _BLAZE_UTIL_ALIGNEDARRAY_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
45 #include <blaze/util/Exception.h>
47 
48 
49 namespace blaze {
50 
51 //=================================================================================================
52 //
53 // CLASS DEFINITION
54 //
55 //=================================================================================================
56 
57 //*************************************************************************************************
93 template< typename Type // Data type of the elements
94  , size_t N // Number of elements
95  , size_t Alignment = AlignmentOf_v<Type> > // Array alignment
97 {
98  public:
99  //**Type definitions****************************************************************************
100  using ElementType = Type;
101  using Pointer = Type*;
102  using ConstPointer = const Type*;
103  using Reference = Type&;
104  using ConstReference = const Type&;
105  using Iterator = Type*;
106  using ConstIterator = const Type*;
107  //**********************************************************************************************
108 
109  //**Constructors********************************************************************************
112  explicit inline AlignedArray();
113 
114  template< typename... Ts >
115  explicit inline constexpr AlignedArray( const Ts&... args );
116 
117  AlignedArray( const AlignedArray& ) = default;
118  AlignedArray( AlignedArray&& ) = default;
120  //**********************************************************************************************
121 
122  //**Destructor**********************************************************************************
125  ~AlignedArray() = default;
127  //**********************************************************************************************
128 
129  //**Conversion operators************************************************************************
132  inline constexpr operator Pointer () noexcept;
133  inline constexpr operator ConstPointer() const noexcept;
135  //**********************************************************************************************
136 
137  //**Data access functions***********************************************************************
140  inline constexpr Reference operator[]( size_t index ) noexcept;
141  inline constexpr ConstReference operator[]( size_t index ) const noexcept;
142  inline Reference at( size_t index );
143  inline ConstReference at( size_t index ) const;
144  inline constexpr Pointer data() noexcept;
145  inline constexpr ConstPointer data() const noexcept;
146  inline constexpr Iterator begin () noexcept;
147  inline constexpr ConstIterator begin () const noexcept;
148  inline constexpr ConstIterator cbegin() const noexcept;
149  inline constexpr Iterator end () noexcept;
150  inline constexpr ConstIterator end () const noexcept;
151  inline constexpr ConstIterator cend () const noexcept;
153  //**********************************************************************************************
154 
155  //**Assignment operators************************************************************************
158  AlignedArray& operator=( const AlignedArray& ) = default;
159  AlignedArray& operator=( AlignedArray&& ) = default;
161  //**********************************************************************************************
162 
163  //**Utility functions***************************************************************************
166  inline constexpr size_t size() const noexcept;
168  //**********************************************************************************************
169 
170  private:
171  //**Member variables****************************************************************************
175  alignas( Alignment ) Type v_[ N > 0UL ? N : 1UL ];
176 
177 
178  //**********************************************************************************************
179 
180  //**Compile time checks*************************************************************************
185  //**********************************************************************************************
186 };
187 //*************************************************************************************************
188 
189 
190 
191 
192 //=================================================================================================
193 //
194 // CONSTRUCTORS
195 //
196 //=================================================================================================
197 
198 //*************************************************************************************************
201 template< typename Type // Data type of the elements
202  , size_t N // Number of elements
203  , size_t Alignment > // Array alignment
204 inline AlignedArray<Type,N,Alignment>::AlignedArray()
205 {}
206 //*************************************************************************************************
207 
208 
209 //*************************************************************************************************
214 template< typename Type // Data type of the elements
215  , size_t N // Number of elements
216  , size_t Alignment > // Array alignment
217 template< typename... Ts > // Types of the array initializers
218 inline constexpr AlignedArray<Type,N,Alignment>::AlignedArray( const Ts&... args )
219  : v_{ args... } // The aligned array
220 {}
221 //*************************************************************************************************
222 
223 
224 
225 
226 //=================================================================================================
227 //
228 // CONVERSION OPERATORS
229 //
230 //=================================================================================================
231 
232 //*************************************************************************************************
237 template< typename Type // Data type of the elements
238  , size_t N // Number of elements
239  , size_t Alignment > // Array alignment
241 {
242  return v_;
243 }
244 //*************************************************************************************************
245 
246 
247 //*************************************************************************************************
252 template< typename Type // Data type of the elements
253  , size_t N // Number of elements
254  , size_t Alignment > // Array alignment
256 {
257  return v_;
258 }
259 //*************************************************************************************************
260 
261 
262 
263 
264 //=================================================================================================
265 //
266 // DATA ACCESS FUNCTIONS
267 //
268 //=================================================================================================
269 
270 //*************************************************************************************************
278 template< typename Type // Data type of the elements
279  , size_t N // Number of elements
280  , size_t Alignment > // Array alignment
281 inline constexpr typename AlignedArray<Type,N,Alignment>::Reference
283 {
284  return v_[index];
285 }
286 //*************************************************************************************************
287 
288 
289 //*************************************************************************************************
297 template< typename Type // Data type of the elements
298  , size_t N // Number of elements
299  , size_t Alignment > // Array alignment
300 inline constexpr typename AlignedArray<Type,N,Alignment>::ConstReference
301  AlignedArray<Type,N,Alignment>::operator[]( size_t index ) const noexcept
302 {
303  return v_[index];
304 }
305 //*************************************************************************************************
306 
307 
308 //*************************************************************************************************
318 template< typename Type // Data type of the elements
319  , size_t N // Number of elements
320  , size_t Alignment > // Array alignment
323 {
324  if( index >= N ) {
325  BLAZE_THROW_OUT_OF_RANGE( "Invalid array access index" );
326  }
327  return v_[index];
328 }
329 //*************************************************************************************************
330 
331 
332 //*************************************************************************************************
342 template< typename Type // Data type of the elements
343  , size_t N // Number of elements
344  , size_t Alignment > // Array alignment
347 {
348  if( index >= N ) {
349  BLAZE_THROW_OUT_OF_RANGE( "Invalid array access index" );
350  }
351  return v_[index];
352 }
353 //*************************************************************************************************
354 
355 
356 //*************************************************************************************************
363 template< typename Type // Data type of the elements
364  , size_t N // Number of elements
365  , size_t Alignment > // Array alignment
366 inline constexpr typename AlignedArray<Type,N,Alignment>::Pointer
368 {
369  return v_;
370 }
371 //*************************************************************************************************
372 
373 
374 //*************************************************************************************************
381 template< typename Type // Data type of the elements
382  , size_t N // Number of elements
383  , size_t Alignment > // Array alignment
384 inline constexpr typename AlignedArray<Type,N,Alignment>::ConstPointer
386 {
387  return v_;
388 }
389 //*************************************************************************************************
390 
391 
392 //*************************************************************************************************
397 template< typename Type // Data type of the elements
398  , size_t N // Number of elements
399  , size_t Alignment > // Array alignment
400 inline constexpr typename AlignedArray<Type,N,Alignment>::Iterator
402 {
403  return v_;
404 }
405 //*************************************************************************************************
406 
407 
408 //*************************************************************************************************
413 template< typename Type // Data type of the elements
414  , size_t N // Number of elements
415  , size_t Alignment > // Array alignment
416 inline constexpr typename AlignedArray<Type,N,Alignment>::ConstIterator
418 {
419  return v_;
420 }
421 //*************************************************************************************************
422 
423 
424 //*************************************************************************************************
429 template< typename Type // Data type of the elements
430  , size_t N // Number of elements
431  , size_t Alignment > // Array alignment
432 inline constexpr typename AlignedArray<Type,N,Alignment>::ConstIterator
434 {
435  return v_;
436 }
437 //*************************************************************************************************
438 
439 
440 //*************************************************************************************************
445 template< typename Type // Data type of the elements
446  , size_t N // Number of elements
447  , size_t Alignment > // Array alignment
448 inline constexpr typename AlignedArray<Type,N,Alignment>::Iterator
450 {
451  return v_ + N;
452 }
453 //*************************************************************************************************
454 
455 
456 //*************************************************************************************************
461 template< typename Type // Data type of the elements
462  , size_t N // Number of elements
463  , size_t Alignment > // Array alignment
464 inline constexpr typename AlignedArray<Type,N,Alignment>::ConstIterator
466 {
467  return v_ + N;
468 }
469 //*************************************************************************************************
470 
471 
472 //*************************************************************************************************
477 template< typename Type // Data type of the elements
478  , size_t N // Number of elements
479  , size_t Alignment > // Array alignment
480 inline constexpr typename AlignedArray<Type,N,Alignment>::ConstIterator
482 {
483  return v_ + N;
484 }
485 //*************************************************************************************************
486 
487 
488 
489 
490 //=================================================================================================
491 //
492 // UTILITY FUNCTIONS
493 //
494 //=================================================================================================
495 
496 //*************************************************************************************************
501 template< typename Type // Data type of the elements
502  , size_t N // Number of elements
503  , size_t Alignment > // Array alignment
504 inline constexpr size_t AlignedArray<Type,N,Alignment>::size() const noexcept
505 {
506  return N;
507 }
508 //*************************************************************************************************
509 
510 } // namespace blaze
511 
512 #endif
constexpr Iterator begin() noexcept
Returns an iterator to the first element of the aligned array.
Definition: AlignedArray.h:401
#define BLAZE_CONSTRAINT_MUST_NOT_BE_CONST(T)
Constraint on the data type.In case the given data type is a const-qualified type,...
Definition: Const.h:79
Header file for the AlignmentOf type trait.
MT::ElementType * data(DenseMatrix< MT, SO > &dm) noexcept
Low-level data access to the dense matrix elements.
Definition: DenseMatrix.h:170
Type * Iterator
Iterator over non-constant elements.
Definition: AlignedArray.h:105
MT::Iterator begin(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:372
Header file for exception macros.
constexpr ConstIterator cbegin() const noexcept
Returns an iterator to the first element of the aligned array.
Definition: AlignedArray.h:433
#define BLAZE_CONSTRAINT_MUST_NOT_BE_VOLATILE(T)
Constraint on the data type.In case the given data type is a volatile-qualified type,...
Definition: Volatile.h:79
Type * Pointer
Pointer to a non-constant array element.
Definition: AlignedArray.h:101
MT::ConstIterator cend(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:482
MT::ConstIterator cbegin(const Matrix< MT, SO > &matrix, size_t i)
Returns an iterator to the first element of row/column i.
Definition: Matrix.h:416
AlignedArray()
The default constructor for AlignedArray.
Definition: AlignedArray.h:204
Type & Reference
Reference to a non-constant array element.
Definition: AlignedArray.h:103
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#define BLAZE_THROW_OUT_OF_RANGE(MESSAGE)
Macro for the emission of a std::out_of_range exception.This macro encapsulates the default way of Bl...
Definition: Exception.h:331
Constraint on the data type.
Reference at(size_t index)
Checked access to the array elements.
Definition: AlignedArray.h:322
Type ElementType
Type of the array elements.
Definition: AlignedArray.h:100
const Type & ConstReference
Reference to a constant array element.
Definition: AlignedArray.h:104
MT::Iterator end(Matrix< MT, SO > &matrix, size_t i)
Returns an iterator just past the last element of row/column i.
Definition: Matrix.h:438
Constraint on the data type.
constexpr Pointer data() noexcept
Low-level data access to the array elements.
Definition: AlignedArray.h:367
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
constexpr Iterator end() noexcept
Returns an iterator just past the last element of the aligned array.
Definition: AlignedArray.h:449
const Type * ConstPointer
Pointer to a constant array element.
Definition: AlignedArray.h:102
Implementation of a static array with a fixed alignment.The AlignedArray class template represents a ...
Definition: AlignedArray.h:96
constexpr ConstIterator cend() const noexcept
Returns an iterator just past the last element of the aligned array.
Definition: AlignedArray.h:481
constexpr size_t size() const noexcept
Returns the current size/dimension of the aligned array.
Definition: AlignedArray.h:504
const Type * ConstIterator
Iterator over constant elements.
Definition: AlignedArray.h:106