view: add make_byte_view convenience method.
This commit is contained in:
parent
8c8a252d9f
commit
db4f09628f
38
view.hpp
38
view.hpp
@ -583,6 +583,44 @@ namespace util {
|
||||
make_view (std::basic_string<CharT,TraitsT,AllocT>&&) = delete;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// 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...
|
||||
template <typename T>
|
||||
view<std::byte*>
|
||||
make_byte_view (T &t)
|
||||
{
|
||||
auto first = reinterpret_cast<std::byte*> (&t);
|
||||
auto last = first + sizeof (t);
|
||||
return { first, last };
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
view<std::byte*>
|
||||
make_byte_view (T&&) = delete;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
view<const std::byte*>
|
||||
make_byte_view (const T &t)
|
||||
{
|
||||
auto first = reinterpret_cast<std::byte*> (&t);
|
||||
auto last = first + sizeof (t);
|
||||
return { first, last };
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
view<const std::byte*>
|
||||
make_byte_view (const T &&t) = delete;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <
|
||||
typename BeginA, typename EndA,
|
||||
|
Loading…
Reference in New Issue
Block a user