tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
aligned_storage.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_TYPE_TRAITS_ALIGNED_STORAGE_HPP
4#define TETL_TYPE_TRAITS_ALIGNED_STORAGE_HPP
5
9
10namespace etl {
11
12namespace detail {
13// With this change, types smaller then 16 bytes are aligned to their size. This
14// equals the behavoir from libc++ and MSVC-STL. Copied from
15// https://github.com/WG21-SG14/SG14/commit/98baf1aeab
16// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61458#c10
17template <etl::size_t Cap>
18union aligned_storage_impl {
19 template <typename T>
20 using maybe = conditional_t<(Cap >= sizeof(T)), T, char>;
21
22 struct double1 {
23 double a;
24 };
25
26 struct double4 {
27 double a[4];
28 };
29
30 char real_data[Cap];
31 maybe<int> a;
32 maybe<long> b;
33 maybe<long long> c;
34 maybe<void*> d;
35 maybe<void (*)()> e;
36 maybe<double1> f;
37 maybe<double4> g;
38 maybe<long double> h;
39};
40} // namespace detail
41
49template <size_t Len, size_t Align = alignof(detail::aligned_storage_impl<Len>)>
51 struct type {
52 alignas(Align) unsigned char data[Len];
53 };
54};
55
56template <size_t Len, size_t Align = alignof(detail::aligned_storage_impl<Len>)>
58
59} // namespace etl
60
61#endif // TETL_TYPE_TRAITS_ALIGNED_STORAGE_HPP
Definition adjacent_find.hpp:8
typename conditional< B, T, F >::type conditional_t
Definition conditional.hpp:21
typename aligned_storage< Len, Align >::type aligned_storage_t
Definition aligned_storage.hpp:57
Definition aligned_storage.hpp:51
unsigned char data[Len]
Definition aligned_storage.hpp:52
Provides the nested type type, which is a trivial standard-layout type suitable for use as uninitiali...
Definition aligned_storage.hpp:50