Blaze 3.9
SmallArrayData.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_UTIL_SMALLARRAY_SMALLARRAYDATA_H_
36#define _BLAZE_UTIL_SMALLARRAY_SMALLARRAYDATA_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
43#include <blaze/util/Types.h>
45
46
47namespace blaze {
48
49//=================================================================================================
50//
51// CLASS DEFINITION
52//
53//=================================================================================================
54
55//*************************************************************************************************
63template< typename T // Data type of the elements
64 , size_t N > // Number of preallocated elements
65struct SmallArrayData
66{
67 public:
68 //**Constructors********************************************************************************
71 constexpr SmallArrayData() noexcept;
73 //**********************************************************************************************
74
75 //**Data access functions***********************************************************************
78 constexpr T* array() noexcept;
79 constexpr const T* array() const noexcept;
81 //**********************************************************************************************
82
83 private:
84 //**Member variables****************************************************************************
87 alignas( AlignmentOf_v<T> ) byte_t v_[N*sizeof(T)];
89 //**********************************************************************************************
90};
92//*************************************************************************************************
93
94
95//*************************************************************************************************
101template< typename T // Data type of the elements
102 , size_t N > // Number of preallocated elements
103constexpr SmallArrayData<T,N>::SmallArrayData() noexcept
104 // v_ is intentionally not initialized
105{}
107//*************************************************************************************************
108
109
110//*************************************************************************************************
116template< typename T // Data type of the elements
117 , size_t N > // Number of preallocated elements
118constexpr T* SmallArrayData<T,N>::array() noexcept
119{
120 return reinterpret_cast<T*>( v_ );
121}
123//*************************************************************************************************
124
125
126//*************************************************************************************************
132template< typename T // Data type of the elements
133 , size_t N > // Number of preallocated elements
134constexpr const T* SmallArrayData<T,N>::array() const noexcept
135{
136 return reinterpret_cast<const T*>( v_ );
137}
139//*************************************************************************************************
140
141
142
143
144//=================================================================================================
145//
146// CLASS TEMPLATE SPECIALIZATION FOR N = 0
147//
148//=================================================================================================
149
150//*************************************************************************************************
157template< typename T > // Data type of the elements
158struct SmallArrayData<T,0UL>
159{
160 public:
161 //**Data access functions***********************************************************************
164 constexpr T* array() noexcept;
165 constexpr const T* array() const noexcept;
167 //**********************************************************************************************
168};
170//*************************************************************************************************
171
172
173//*************************************************************************************************
179template< typename T > // Data type of the elements
180constexpr T* SmallArrayData<T,0UL>::array() noexcept
181{
182 return nullptr;
183}
185//*************************************************************************************************
186
187
188//*************************************************************************************************
194template< typename T > // Data type of the elements
195constexpr const T* SmallArrayData<T,0UL>::array() const noexcept
196{
197 return nullptr;
198}
200//*************************************************************************************************
201
202} // namespace blaze
203
204#endif
Header file for the AlignmentOf type trait.
constexpr size_t AlignmentOf_v
Auxiliary variable template for the AlignmentOf type trait.
Definition: AlignmentOf.h:239
unsigned char byte_t
Byte data type of the Blaze library.
Definition: Types.h:79
Header file for basic type definitions.