My Project
aligned_union.hpp
Go to the documentation of this file.
1 
28 #ifndef BSL_ALIGNED_UNION_HPP
29 #define BSL_ALIGNED_UNION_HPP
30 
31 #include "byte.hpp"
32 #include "cstdint.hpp"
33 #include "integer_sequence.hpp"
34 
35 namespace bsl
36 {
51  template<typename GUARD, bsl::uintmax LEN, typename... TYPES>
52  struct aligned_union final
53  {
54  static_assert(sizeof...(TYPES) > 0, "empty aligned_union is not supported");
55 
57  static constexpr bsl::uintmax alignment_value{index_sequence<alignof(TYPES)...>::max()};
58 
64  struct type
65  {
67  alignas(alignment_value) byte m_data[ // NOLINT
68  index_sequence<LEN, sizeof(TYPES)...>::max()];
69  };
70  };
71 
73  template<bsl::uintmax LEN, typename... TYPES>
74  using aligned_union_t = typename aligned_union<void, LEN, TYPES...>::type;
75 }
76 
77 #endif
Implements the std::aligned_union type interface.
Definition: aligned_union.hpp:64
Implements the std::aligned_union interface. The only real difference is we use "m_data" instead of "...
Definition: aligned_union.hpp:52
byte m_data[index_sequence< LEN, sizeof(TYPES)... >::max()]
defines the storage component of the bsl::aligned_union
Definition: aligned_union.hpp:68
static constexpr bsl::uintmax alignment_value
the alignment of the union.
Definition: aligned_union.hpp:57
The class template std::integer_sequence represents a compile-time sequence of integers....
Definition: integer_sequence.hpp:52
typename aligned_union< void, LEN, TYPES... >::type aligned_union_t
a helper that reduces the verbosity of bsl::aligned_union
Definition: aligned_union.hpp:74
::uintmax_t uintmax
defines a unsigned integer with the maximum possible size
Definition: cstdint.hpp:97