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 
47 namespace blaze {
48 
49 //=================================================================================================
50 //
51 // CLASS DEFINITION
52 //
53 //=================================================================================================
54 
55 //*************************************************************************************************
63 template< typename T // Data type of the elements
64  , size_t N > // Number of preallocated elements
65 struct SmallArrayData
66 {
67  public:
68  //**Constructors********************************************************************************
71  inline constexpr SmallArrayData() noexcept;
73  //**********************************************************************************************
74 
75  //**Data access functions***********************************************************************
78  inline constexpr T* array() noexcept;
79  inline constexpr const T* array() const noexcept;
81  //**********************************************************************************************
82 
83  private:
84  //**Member variables****************************************************************************
87  alignas( AlignmentOf_v<T> ) byte_t v_[N*sizeof(T)];
88 
89  //**********************************************************************************************
90 };
92 //*************************************************************************************************
93 
94 
95 //*************************************************************************************************
101 template< typename T // Data type of the elements
102  , size_t N > // Number of preallocated elements
103 constexpr SmallArrayData<T,N>::SmallArrayData() noexcept
104  // v_ is intentionally not initialized
105 {}
107 //*************************************************************************************************
108 
109 
110 //*************************************************************************************************
116 template< typename T // Data type of the elements
117  , size_t N > // Number of preallocated elements
118 inline constexpr T* SmallArrayData<T,N>::array() noexcept
119 {
120  return reinterpret_cast<T*>( v_ );
121 }
123 //*************************************************************************************************
124 
125 
126 //*************************************************************************************************
132 template< typename T // Data type of the elements
133  , size_t N > // Number of preallocated elements
134 inline constexpr 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 //*************************************************************************************************
157 template< typename T > // Data type of the elements
158 struct SmallArrayData<T,0UL>
159 {
160  public:
161  //**Data access functions***********************************************************************
164  inline constexpr T* array() noexcept;
165  inline constexpr const T* array() const noexcept;
167  //**********************************************************************************************
168 };
170 //*************************************************************************************************
171 
172 
173 //*************************************************************************************************
179 template< typename T > // Data type of the elements
180 inline constexpr T* SmallArrayData<T,0UL>::array() noexcept
181 {
182  return nullptr;
183 }
185 //*************************************************************************************************
186 
187 
188 //*************************************************************************************************
194 template< typename T > // Data type of the elements
195 inline constexpr 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.
Header file for basic type definitions.
unsigned char byte_t
Byte data type of the Blaze library.The byte data type is guaranteed to be an integral data type of s...
Definition: Types.h:79
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
constexpr size_t AlignmentOf_v
Auxiliary variable template for the AlignmentOf type trait.The AlignmentOf_v variable template provid...
Definition: AlignmentOf.h:238