Pigweed
 
Loading...
Searching...
No Matches
Pw_span_cast

Functions

template<class ResultT , size_t kSourceExtentBytes>
internal::SpanFromBytes< ResultT, kSourceExtentBytes > pw::span_cast (span< std::byte, kSourceExtentBytes > bytes)
 

Detailed Description

Function Documentation

◆ span_cast()

template<class ResultT , size_t kSourceExtentBytes>
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).

Template Parameters
ResultTThe 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.
kSourceExtentBytesThe extent of the source byte span. This is normally inferred and need not be explicitly provided.