31#ifndef ETL_ALIGNMENT_INCLUDED
32#define ETL_ALIGNMENT_INCLUDED
36#include "static_assert.h"
57 alignment_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
58 :
exception(reason_, file_name_, line_number_)
66 class alignment_error :
public alignment_exception
70 alignment_error(string_type file_name_, numeric_type line_number_)
71 : alignment_exception(ETL_ERROR_TEXT(
"alignment:error", ETL_ALIGNMENT_FILE_ID
"A"), file_name_, line_number_)
79 class typed_storage_error :
public alignment_exception
83 typed_storage_error(string_type file_name_, numeric_type line_number_)
84 : alignment_exception(ETL_ERROR_TEXT(
"typed_storage:error", ETL_ALIGNMENT_FILE_ID
"B"), file_name_, line_number_)
92 inline bool is_aligned(
const void* p,
size_t required_alignment)
94 uintptr_t address =
reinterpret_cast<uintptr_t
>(p);
95 return (address % required_alignment) == 0U;
101 template <
size_t Alignment>
104 uintptr_t address =
reinterpret_cast<uintptr_t
>(p);
105 return (address % Alignment) == 0U;
111 template <
typename T>
117 namespace private_alignment
123 template <
bool Is_Match,
size_t Alignment,
typename... TRest>
124 class type_with_alignment_matcher;
127 template <
size_t Alignment,
typename T1,
typename... TRest>
128 class type_with_alignment_matcher<true, Alignment, T1, TRest...>
136 template <
size_t Alignment,
typename T1,
typename T2,
typename... TRest>
141 typedef typename type_with_alignment_matcher < Alignment <= etl::alignment_of<T2>::value , Alignment, T2, TRest... > ::type type;
145 template <
size_t Alignment,
typename T1>
156 template <
size_t Alignment,
typename T1,
typename... T>
161 typedef typename type_with_alignment_matcher<Alignment <= etl::alignment_of<T1>::value, Alignment, T1, T...>::type type;
167 template <
bool Is_Match,
const size_t Alignment,
typename T1 = void,
typename T2 = void,
typename T3 = void,
typename T4 = void,
168 typename T5 = void,
typename T6 = void,
typename T7 = void,
typename T8 =
void>
172 template <
size_t Alignment,
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6,
typename T7,
typename T8>
181 template <
size_t Alignment,
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6,
typename T7,
typename T8>
190 template <
size_t Alignment>
201 template <
size_t Alignment,
typename T1,
typename T2 = void,
typename T3 = void,
typename T4 = void,
202 typename T5 = void,
typename T6 = void,
typename T7 = void,
typename T8 =
void>
216 template <
size_t Alignment>
222 typedef struct {
alignas(Alignment)
char dummy; } type;
224 #if ETL_NOT_USING_64BIT_TYPES
225 typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, float, double, void*>::type type;
227 typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, int64_t, float, double, void*>::type type;
235 template <
size_t Alignment>
236 using type_with_alignment_t =
typename type_with_alignment<Alignment>::type;
244 template <
size_t Length, const
size_t Alignment>
250 template <
typename T>
259 template <
typename T>
260 operator const T& ()
const
268 template <
typename T>
272 return reinterpret_cast<T*
>(data);
276 template <
typename T>
277 operator const T* ()
const
280 return reinterpret_cast<const T*
>(data);
284 template <
typename T>
293 template <
typename T>
302 template <
typename T>
306 return reinterpret_cast<T*
>(data);
310 template <
typename T>
314 return reinterpret_cast<const T*
>(data);
317#if ETL_USING_CPP11 && !defined(ETL_COMPILER_ARM5)
318 alignas(Alignment)
char data[Length];
323 typename etl::type_with_alignment<Alignment>::type etl_alignment_type;
330 template <
size_t Length, const
size_t Alignment>
338 template <
size_t Length,
typename T>
344 template <
size_t Length,
typename T>
345 using aligned_storage_as_t =
typename aligned_storage_as<Length, T>::type;
356 template <
typename T>
361 typedef T value_type;
362 typedef T& reference;
363 typedef const T& const_reference;
365 typedef const T* const_pointer;
370 typed_storage() ETL_NOEXCEPT
379 template <
typename... TArgs>
380 typed_storage(TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
383 create(etl::forward<TArgs>(args)...);
389 template <
typename T1>
399 template <
typename T1,
typename T2>
409 template <
typename T1,
typename T2,
typename T3>
419 template <
typename T1,
typename T2,
typename T3,
typename T4>
450 template <
typename... TArgs>
451 reference create(TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
463 template <
typename T1>
467 pointer p = ::new (&storage.value) value_type(t1);
476 template <
typename T1,
typename T2>
477 reference
create(
const T1& t1,
const T2& t2)
480 pointer p = ::new (&storage.value) value_type(t1, t2);
489 template <
typename T1,
typename T2,
typename T3>
490 reference
create(
const T1& t1,
const T2& t2,
const T3& t3)
493 pointer p = ::new (&storage.value) value_type(t1, t2, t3);
502 template <
typename T1,
typename T2,
typename T3,
typename T4>
503 reference
create(
const T1& t1,
const T2& t2,
const T3& t3,
const T4& t4)
506 pointer p = ::new (&storage.value) value_type(t1, t2, t3, t4);
527 pointer
operator->() ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
531 return &storage.value;
537 const_pointer
operator->() const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
541 return &storage.value;
547 reference
operator*() ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
555 const_reference
operator*() const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
570 union_type() ETL_NOEXCEPT
575 ~union_type() ETL_NOEXCEPT
594 template <
typename T>
599 typedef T value_type;
600 typedef T& reference;
601 typedef const T& const_reference;
603 typedef const T* const_pointer;
605 template <
typename U>
612 : pbuffer(reinterpret_cast<T*>(pbuffer_)),
622 template <
typename... TArgs>
623 typed_storage_ext(
void* pbuffer_, TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
624 : pbuffer(reinterpret_cast<T*>(pbuffer_))
628 create(etl::forward<TArgs>(args)...);
635 typed_storage_ext(typed_storage_ext<T>&& other) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
636 : pbuffer(other.pbuffer)
639 other.pbuffer = ETL_NULLPTR;
646 template <
typename T1>
648 : pbuffer(reinterpret_cast<T*>(pbuffer_))
658 template <
typename T1,
typename T2>
660 : pbuffer(reinterpret_cast<T*>(pbuffer_))
670 template <
typename T1,
typename T2,
typename T3>
672 : pbuffer(reinterpret_cast<T*>(pbuffer_))
682 template <
typename T1,
typename T2,
typename T3,
typename T4>
684 : pbuffer(reinterpret_cast<T*>(pbuffer_))
715 template <
typename... TArgs>
716 reference create(TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
728 template <
typename T1>
732 pointer p = ::new (pbuffer) value_type(t1);
741 template <
typename T1,
typename T2>
742 reference
create(
const T1& t1,
const T2& t2)
745 pointer p = ::new (pbuffer) value_type(t1, t2);
754 template <
typename T1,
typename T2,
typename T3>
755 reference
create(
const T1& t1,
const T2& t2,
const T3& t3)
758 pointer p = ::new (pbuffer) value_type(t1, t2, t3);
767 template <
typename T1,
typename T2,
typename T3,
typename T4>
768 reference
create(
const T1& t1,
const T2& t2,
const T3& t3,
const T4& t4)
771 pointer p = ::new (pbuffer) value_type(t1, t2, t3, t4);
792 pointer
operator->() ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
802 const_pointer
operator->() const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
812 reference
operator*() ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
820 const_reference
operator*() const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
837 template <
typename T>
840 using ETL_OR_STD::swap;
842 swap(lhs.pbuffer, rhs.pbuffer);
843 swap(lhs.valid, rhs.valid);
void swap(etl::array_view< T > &lhs, etl::array_view< T > &rhs) ETL_NOEXCEPT
Swaps the values.
Definition array_view.h:650
Memory misalignment exception.
Definition alignment.h:67
Definition alignment.h:204
Definition alignment.h:169
Typed storage exception.
Definition alignment.h:80
Definition alignment.h:596
typed_storage_ext(void *pbuffer_) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
Constructor.
Definition alignment.h:611
typed_storage_ext(void *pbuffer_, const T1 &t1, const T2 &t2)
Constructs the instance of T with types T1, T2.
Definition alignment.h:659
const_reference operator*() const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
Definition alignment.h:820
reference create(const T1 &t1, const T2 &t2)
Definition alignment.h:742
pointer operator->() ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
Definition alignment.h:792
reference create(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4)
Definition alignment.h:768
reference create(const T1 &t1, const T2 &t2, const T3 &t3)
Definition alignment.h:755
typed_storage_ext(void *pbuffer_, const T1 &t1)
Constructs the instance of T with type T1.
Definition alignment.h:647
void destroy() ETL_NOEXCEPT
Calls the destructor of the stored object, if created.
Definition alignment.h:780
~typed_storage_ext() ETL_NOEXCEPT
Definition alignment.h:696
bool has_value() const ETL_NOEXCEPT
Definition alignment.h:705
typed_storage_ext(void *pbuffer_, const T1 &t1, const T2 &t2, const T3 &t3)
Constructs the instance of T with types T1, T2, T3.
Definition alignment.h:671
reference operator*() ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
Definition alignment.h:812
typed_storage_ext(void *pbuffer_, const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4)
Constructs the instance of T with types T1, T2, T3, T4.
Definition alignment.h:683
reference create(const T1 &t1)
Definition alignment.h:729
const_pointer operator->() const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
Definition alignment.h:802
Definition alignment.h:358
reference create(const T1 &t1, const T2 &t2)
Definition alignment.h:477
reference create(const T1 &t1)
Definition alignment.h:464
reference operator*() ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
Definition alignment.h:547
void destroy() ETL_NOEXCEPT
Calls the destructor of the stored object, if created.
Definition alignment.h:515
bool has_value() const ETL_NOEXCEPT
Definition alignment.h:440
typed_storage(const T1 &t1)
Constructs the instance of T with type T1.
Definition alignment.h:390
const_reference operator*() const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
Definition alignment.h:555
~typed_storage() ETL_NOEXCEPT
Definition alignment.h:431
const_pointer operator->() const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
Definition alignment.h:537
reference create(const T1 &t1, const T2 &t2, const T3 &t3)
Definition alignment.h:490
pointer operator->() ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
Definition alignment.h:527
typed_storage(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4)
Constructs the instance of T with types T1, T2, T3, T4.
Definition alignment.h:420
typed_storage(const T1 &t1, const T2 &t2, const T3 &t3)
Constructs the instance of T with types T1, T2, T3.
Definition alignment.h:410
reference create(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4)
Definition alignment.h:503
typed_storage(const T1 &t1, const T2 &t2)
Constructs the instance of T with types T1, T2.
Definition alignment.h:400
Definition alignment.h:218
Definition alignment.h:246
Definition alignment.h:340
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
ETL_CONSTEXPR exception(string_type reason_, string_type, numeric_type line_)
Constructor.
Definition exception.h:69
Definition exception.h:47
add_rvalue_reference
Definition type_traits_generator.h:1413
is_same
Definition type_traits_generator.h:1104
bitset_ext
Definition absolute.h:39
ETL_CONSTEXPR14 void swap(etl::typed_storage_ext< T > &lhs, etl::typed_storage_ext< T > &rhs) ETL_NOEXCEPT
Swap two etl::typed_storage_ext.
Definition alignment.h:838
T * create(Args &&... args)
Creates the object from a type. Variadic parameter constructor.
Definition variant_pool_generator.h:348
bool is_aligned(const void *p, size_t required_alignment)
Check that 'p' has 'required_alignment'.
Definition alignment.h:92
Definition alignment.h:248
const T * get_address() const
Get address as const T pointer.
Definition alignment.h:311
T * get_address()
Get address as T pointer.
Definition alignment.h:303
const T & get_reference() const
Get address as const T reference.
Definition alignment.h:294
T & get_reference()
Get address as T reference.
Definition alignment.h:285