view: allow multibyte casts in make_byte_view
This commit is contained in:
parent
cc2d11f102
commit
60bd71a57b
25
view.hpp
25
view.hpp
@ -576,32 +576,31 @@ namespace cruft {
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// calculates a byte oriented view over an arbitrary type
|
||||
//
|
||||
// useful for passing in memory structures to file descriptors and the
|
||||
// like. but the consequences of endian conversion is on the user...
|
||||
//
|
||||
// we have to be careful that rval-references and other temporaries aren't
|
||||
// accepted in this signature.
|
||||
/// Calculates a word oriented view over an arbitrary type
|
||||
///
|
||||
/// Useful for passing in memory structures to file descriptors and the
|
||||
/// like. but the consequences of endian conversion is on the user...
|
||||
///
|
||||
/// We have to be careful that rval-references and other temporaries aren't
|
||||
/// accepted in this signature.
|
||||
template <
|
||||
typename ByteT = std::byte,
|
||||
typename WordT = std::byte,
|
||||
typename T
|
||||
>
|
||||
auto
|
||||
make_byte_view (T &t)
|
||||
{
|
||||
static_assert (std::is_integral_v<ByteT>);
|
||||
static_assert (sizeof (T) % sizeof (ByteT) == 0);
|
||||
static_assert (sizeof (T) % sizeof (WordT) == 0);
|
||||
|
||||
using cursor_type = std::conditional_t<
|
||||
std::is_const_v<T>,
|
||||
ByteT const*,
|
||||
ByteT*
|
||||
WordT const*,
|
||||
WordT*
|
||||
>;
|
||||
|
||||
return view {
|
||||
cast::alignment<cursor_type> (&t),
|
||||
sizeof (T) / sizeof (ByteT)
|
||||
sizeof (T) / sizeof (WordT)
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user