Functions | |
template<class ResultT , size_t kSourceExtentBytes> | |
internal::SpanFromBytes< ResultT, kSourceExtentBytes > | pw::span_cast (span< std::byte, kSourceExtentBytes > bytes) |
internal::SpanFromBytes< ResultT, kSourceExtentBytes > pw::span_cast | ( | span< std::byte, kSourceExtentBytes > | bytes | ) |
Casts a pw::span<std::byte>
(ByteSpan
) to a span of a different type.
This function is only safe to use if the underlying data is actually of the specified type. You cannot safely use this function to reinterpret e.g. a raw byte array from malloc()
as a span of integers.
This function is essentially the inverse of pw::as_writable_bytes
.
If kSourceExtentBytes
is dynamic_extent
, the returned span also has a dynamic extent. Otherwise, the returned span has a static extent of kSourceExtentBytes / sizeof(ResultT)
.
ResultT | The type of the returned span. Must be one byte to avoid misuse and violation of the strict aliasing rule. This restriction might be lifted in the future. |
kSourceExtentBytes | The extent of the source byte span. This is normally inferred and need not be explicitly provided. |