@@ -133,17 +133,14 @@ namespace epee
133
133
return {src.data (), src.size ()};
134
134
}
135
135
136
- template <typename T>
137
- constexpr bool has_padding () noexcept
138
- {
139
- return !std::is_standard_layout<T>() || alignof (T) != 1 ;
140
- }
141
-
142
136
// ! \return Cast data from `src` as `span<const std::uint8_t>`.
143
137
template <typename T>
144
138
span<const std::uint8_t > to_byte_span (const span<const T> src) noexcept
145
139
{
146
- static_assert (!has_padding<T>(), " source type may have padding" );
140
+ static_assert (!std::is_empty<T>(), " empty value types will not work -> sizeof == 1" );
141
+ static_assert (std::is_standard_layout<T>(), " type must have standard layout" );
142
+ static_assert (std::is_trivially_copyable<T>(), " type must be trivially copyable" );
143
+ static_assert (alignof (T) == 1 , " type may have padding" );
147
144
return {reinterpret_cast <const std::uint8_t *>(src.data ()), src.size_bytes ()};
148
145
}
149
146
@@ -153,7 +150,9 @@ namespace epee
153
150
{
154
151
using value_type = typename T::value_type;
155
152
static_assert (!std::is_empty<value_type>(), " empty value types will not work -> sizeof == 1" );
156
- static_assert (!has_padding<value_type>(), " source value type may have padding" );
153
+ static_assert (std::is_standard_layout<value_type>(), " value type must have standard layout" );
154
+ static_assert (std::is_trivially_copyable<value_type>(), " value type must be trivially copyable" );
155
+ static_assert (alignof (value_type) == 1 , " value type may have padding" );
157
156
return {reinterpret_cast <std::uint8_t *>(src.data ()), src.size () * sizeof (value_type)};
158
157
}
159
158
@@ -162,7 +161,9 @@ namespace epee
162
161
span<const std::uint8_t > as_byte_span (const T& src) noexcept
163
162
{
164
163
static_assert (!std::is_empty<T>(), " empty types will not work -> sizeof == 1" );
165
- static_assert (!has_padding<T>(), " source type may have padding" );
164
+ static_assert (std::is_standard_layout<T>(), " type must have standard layout" );
165
+ static_assert (std::is_trivially_copyable<T>(), " type must be trivially copyable" );
166
+ static_assert (alignof (T) == 1 , " type may have padding" );
166
167
return {reinterpret_cast <const std::uint8_t *>(std::addressof (src)), sizeof (T)};
167
168
}
168
169
@@ -171,7 +172,9 @@ namespace epee
171
172
span<std::uint8_t > as_mut_byte_span (T& src) noexcept
172
173
{
173
174
static_assert (!std::is_empty<T>(), " empty types will not work -> sizeof == 1" );
174
- static_assert (!has_padding<T>(), " source type may have padding" );
175
+ static_assert (std::is_standard_layout<T>(), " type must have standard layout" );
176
+ static_assert (std::is_trivially_copyable<T>(), " type must be trivially copyable" );
177
+ static_assert (alignof (T) == 1 , " type may have padding" );
175
178
return {reinterpret_cast <std::uint8_t *>(std::addressof (src)), sizeof (T)};
176
179
}
177
180
0 commit comments