@@ -102,34 +102,79 @@ namespace etl
102
102
103
103
namespace private_alignment
104
104
{
105
+ #if ETL_USING_CPP11
105
106
// ***************************************************************************
106
107
// Matcher.
107
108
// ***************************************************************************
108
- template <bool IS_MATCH, const size_t ALIGNMENT, typename T1 = void , typename T2 = void , typename T3 = void , typename T4 = void ,
109
+ template <bool Is_Match, size_t Alignment, typename ... TRest>
110
+ class type_with_alignment_matcher ;
111
+
112
+ // Matching alignment.
113
+ template <size_t Alignment, typename T1, typename ... TRest>
114
+ class type_with_alignment_matcher <true , Alignment, T1, TRest...>
115
+ {
116
+ public:
117
+
118
+ typedef T1 type;
119
+ };
120
+
121
+ // Non-matching alignment
122
+ template <size_t Alignment, typename T1, typename T2, typename ... TRest>
123
+ class type_with_alignment_matcher <false , Alignment, T1, T2, TRest...>
124
+ {
125
+ public:
126
+
127
+ typedef typename type_with_alignment_matcher < Alignment <= etl::alignment_of<T2>::value , Alignment, T2, TRest... > ::type type;
128
+ };
129
+
130
+ // Non-matching alignment, none left.
131
+ template <size_t Alignment, typename T1>
132
+ class type_with_alignment_matcher <false , Alignment, T1>
133
+ {
134
+ public:
135
+
136
+ typedef char type;
137
+ };
138
+
139
+ // ***************************************************************************
140
+ // Helper.
141
+ // ***************************************************************************
142
+ template <size_t Alignment, typename T1, typename ... T>
143
+ class type_with_alignment_helper
144
+ {
145
+ public:
146
+
147
+ typedef typename type_with_alignment_matcher<Alignment <= etl::alignment_of<T1>::value, Alignment, T1, T...>::type type;
148
+ };
149
+ #else
150
+ // ***************************************************************************
151
+ // Matcher.
152
+ // ***************************************************************************
153
+ template <bool Is_Match, const size_t Alignment, typename T1 = void , typename T2 = void , typename T3 = void , typename T4 = void ,
109
154
typename T5 = void , typename T6 = void , typename T7 = void , typename T8 = void >
110
155
class type_with_alignment_matcher ;
111
156
112
157
// Matching alignment.
113
- template <size_t ALIGNMENT , typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
114
- class type_with_alignment_matcher <true , ALIGNMENT , T1, T2, T3, T4, T5, T6, T7, T8>
158
+ template <size_t Alignment , typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
159
+ class type_with_alignment_matcher <true , Alignment , T1, T2, T3, T4, T5, T6, T7, T8>
115
160
{
116
161
public:
117
162
118
163
typedef T1 type;
119
164
};
120
165
121
166
// Non-matching alignment.
122
- template <size_t ALIGNMENT , typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
123
- class type_with_alignment_matcher <false , ALIGNMENT , T1, T2, T3, T4, T5, T6, T7, T8>
167
+ template <size_t Alignment , typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
168
+ class type_with_alignment_matcher <false , Alignment , T1, T2, T3, T4, T5, T6, T7, T8>
124
169
{
125
170
public:
126
171
127
- typedef typename type_with_alignment_matcher<ALIGNMENT <= etl::alignment_of<T2>::value, ALIGNMENT , T2, T3, T4, T5, T6, T7, T8, void >::type type;
172
+ typedef typename type_with_alignment_matcher<Alignment <= etl::alignment_of<T2>::value, Alignment , T2, T3, T4, T5, T6, T7, T8, void >::type type;
128
173
};
129
174
130
175
// Non-matching alignment, none left.
131
- template <size_t ALIGNMENT >
132
- class type_with_alignment_matcher <false , ALIGNMENT , void , void , void , void , void , void , void , void >
176
+ template <size_t Alignment >
177
+ class type_with_alignment_matcher <false , Alignment , void , void , void , void , void , void , void , void >
133
178
{
134
179
public:
135
180
@@ -139,38 +184,39 @@ namespace etl
139
184
// ***************************************************************************
140
185
// Helper.
141
186
// ***************************************************************************
142
- template <size_t ALIGNMENT , typename T1, typename T2 = void , typename T3 = void , typename T4 = void ,
143
- typename T5 = void , typename T6 = void , typename T7 = void , typename T8 = void >
187
+ template <size_t Alignment , typename T1, typename T2 = void , typename T3 = void , typename T4 = void ,
188
+ typename T5 = void , typename T6 = void , typename T7 = void , typename T8 = void >
144
189
class type_with_alignment_helper
145
190
{
146
191
public:
147
192
148
- typedef typename type_with_alignment_matcher<ALIGNMENT <= etl::alignment_of<T1>::value, ALIGNMENT , T1, T2, T3, T4, T5, T6, T7, T8>::type type;
193
+ typedef typename type_with_alignment_matcher<Alignment <= etl::alignment_of<T1>::value, Alignment , T1, T2, T3, T4, T5, T6, T7, T8>::type type;
149
194
};
195
+ #endif
150
196
}
151
197
152
198
// ***************************************************************************
153
199
// / Gets a type that has the same as the specified alignment.
154
200
// /\ingroup alignment
155
201
// ***************************************************************************
156
- template <size_t ALIGNMENT >
202
+ template <size_t Alignment >
157
203
class type_with_alignment
158
204
{
159
205
public:
160
206
161
207
#if ETL_NOT_USING_64BIT_TYPES
162
- typedef typename private_alignment::type_with_alignment_helper<ALIGNMENT , int_least8_t , int_least16_t , int32_t , float , double , void *>::type type;
208
+ typedef typename private_alignment::type_with_alignment_helper<Alignment , int_least8_t , int_least16_t , int32_t , float , double , void *>::type type;
163
209
#else
164
- typedef typename private_alignment::type_with_alignment_helper<ALIGNMENT , int_least8_t , int_least16_t , int32_t , int64_t , float , double , void *>::type type;
210
+ typedef typename private_alignment::type_with_alignment_helper<Alignment , int_least8_t , int_least16_t , int32_t , int64_t , float , double , void *>::type type;
165
211
#endif
166
212
};
167
213
168
214
// ***************************************************************************
169
215
// / Aligned storage
170
- // / LENGTH should be determined in terms of sizeof()
216
+ // / Length should be determined in terms of sizeof()
171
217
// /\ingroup alignment
172
218
// ***************************************************************************
173
- template <size_t LENGTH , const size_t ALIGNMENT >
219
+ template <size_t Length , const size_t Alignment >
174
220
struct aligned_storage
175
221
{
176
222
struct type
@@ -184,7 +230,7 @@ namespace etl
184
230
template <typename T>
185
231
operator T& ()
186
232
{
187
- ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((ALIGNMENT % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
233
+ ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((Alignment % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
188
234
T* t = *this ;
189
235
return *t;
190
236
}
@@ -193,7 +239,7 @@ namespace etl
193
239
template <typename T>
194
240
operator const T& () const
195
241
{
196
- ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((ALIGNMENT % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
242
+ ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((Alignment % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
197
243
const T* t = *this ;
198
244
return *t;
199
245
}
@@ -202,23 +248,23 @@ namespace etl
202
248
template <typename T>
203
249
operator T* ()
204
250
{
205
- ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((ALIGNMENT % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
251
+ ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((Alignment % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
206
252
return reinterpret_cast <T*>(data);
207
253
}
208
254
209
255
// / Convert to const T pointer.
210
256
template <typename T>
211
257
operator const T* () const
212
258
{
213
- ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((ALIGNMENT % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
259
+ ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((Alignment % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
214
260
return reinterpret_cast <const T*>(data);
215
261
}
216
262
217
263
// / Get address as T reference.
218
264
template <typename T>
219
265
T& get_reference ()
220
266
{
221
- ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((ALIGNMENT % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
267
+ ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((Alignment % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
222
268
T* t = *this ;
223
269
return *t;
224
270
}
@@ -227,7 +273,7 @@ namespace etl
227
273
template <typename T>
228
274
const T& get_reference () const
229
275
{
230
- ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((ALIGNMENT % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
276
+ ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((Alignment % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
231
277
const T* t = *this ;
232
278
return *t;
233
279
}
@@ -236,47 +282,47 @@ namespace etl
236
282
template <typename T>
237
283
T* get_address ()
238
284
{
239
- ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((ALIGNMENT % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
285
+ ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((Alignment % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
240
286
return reinterpret_cast <T*>(data);
241
287
}
242
288
243
289
// / Get address as const T pointer.
244
290
template <typename T>
245
291
const T* get_address () const
246
292
{
247
- ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((ALIGNMENT % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
293
+ ETL_STATIC_ASSERT ((etl::is_same<T*, void *>:: value || ((Alignment % etl::alignment_of<T>::value) == 0 )), " Incompatible alignment" );
248
294
return reinterpret_cast <const T*>(data);
249
295
}
250
296
251
297
#if ETL_USING_CPP11 && !defined(ETL_COMPILER_ARM5)
252
- alignas (ALIGNMENT ) char data[LENGTH ];
298
+ alignas (Alignment ) char data[Length ];
253
299
#else
254
300
union
255
301
{
256
- char data[LENGTH ];
257
- typename etl::type_with_alignment<ALIGNMENT >::type etl_alignment_type; // A POD type that has the same alignment as ALIGNMENT .
302
+ char data[Length ];
303
+ typename etl::type_with_alignment<Alignment >::type etl_alignment_type; // A POD type that has the same alignment as Alignment .
258
304
};
259
305
#endif
260
306
};
261
307
};
262
308
263
309
#if ETL_USING_CPP11
264
- template <size_t LENGTH , const size_t ALIGNMENT >
265
- using aligned_storage_t = typename aligned_storage<LENGTH, ALIGNMENT >::type;
310
+ template <size_t Length , const size_t Alignment >
311
+ using aligned_storage_t = typename aligned_storage<Length, Alignment >::type;
266
312
#endif
267
313
268
314
// ***************************************************************************
269
315
// / Aligned storage as
270
316
// /\ingroup alignment
271
317
// ***************************************************************************
272
- template <size_t LENGTH , typename T>
273
- struct aligned_storage_as : public etl ::aligned_storage<LENGTH , etl::alignment_of<T>::value>
318
+ template <size_t Length , typename T>
319
+ struct aligned_storage_as : public etl ::aligned_storage<Length , etl::alignment_of<T>::value>
274
320
{
275
321
};
276
322
277
323
#if ETL_USING_CPP11
278
- template <size_t LENGTH , typename T>
279
- using aligned_storage_as_t = typename aligned_storage_as<LENGTH , T>::type;
324
+ template <size_t Length , typename T>
325
+ using aligned_storage_as_t = typename aligned_storage_as<Length , T>::type;
280
326
#endif
281
327
}
282
328
0 commit comments