tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
aligned_union.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_TYPE_TRAITS_ALIGNED_UNION_HPP
4#define TETL_TYPE_TRAITS_ALIGNED_UNION_HPP
5
7
8namespace etl {
9
10namespace detail {
11template <typename T>
12[[nodiscard]] constexpr auto vmax(T val) -> T
13{
14 return val;
15}
16
17template <typename T0, typename T1, typename... Ts>
18[[nodiscard]] constexpr auto vmax(T0 val1, T1 val2, Ts... vs) -> T0
19{
20 return (val1 > val2) ? vmax(val1, vs...) : vmax(val2, vs...);
21}
22} // namespace detail
23
34template <size_t Len, typename... Types>
36 static constexpr size_t alignment_value = detail::vmax(alignof(Types)...);
37
38 struct type {
39 alignas(alignment_value) char storage[detail::vmax(Len, sizeof(Types)...)];
40 };
41};
42
43template <size_t Len, typename... Types>
44using aligned_union_t = typename aligned_union<Len, Types...>::type;
45
46} // namespace etl
47
48#endif // TETL_TYPE_TRAITS_ALIGNED_UNION_HPP
auto val(pin_number pin) -> etl::uint16_t
Definition gpio.hpp:37
Definition adjacent_find.hpp:8
typename aligned_union< Len, Types... >::type aligned_union_t
Definition aligned_union.hpp:44
Definition aligned_union.hpp:38
char storage[detail::vmax(Len, sizeof(Types)...)]
Definition aligned_union.hpp:39
Provides the nested type type, which is a trivial standard-layout type of a size and alignment suitab...
Definition aligned_union.hpp:35
static constexpr size_t alignment_value
Definition aligned_union.hpp:36