view: add make_byte_view convenience method.

This commit is contained in:
Danny Robson 2018-02-01 13:48:03 +11:00
parent 8c8a252d9f
commit db4f09628f

View File

@ -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,