From db4f09628f6f4f8ff7f532d2b64998ab549008d5 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 1 Feb 2018 13:48:03 +1100 Subject: [PATCH] view: add make_byte_view convenience method. --- view.hpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/view.hpp b/view.hpp index 6f780c6a..08690431 100644 --- a/view.hpp +++ b/view.hpp @@ -583,6 +583,44 @@ namespace util { make_view (std::basic_string&&) = 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 + view + make_byte_view (T &t) + { + auto first = reinterpret_cast (&t); + auto last = first + sizeof (t); + return { first, last }; + } + + + //------------------------------------------------------------------------- + template + view + make_byte_view (T&&) = delete; + + + //------------------------------------------------------------------------- + template + view + make_byte_view (const T &t) + { + auto first = reinterpret_cast (&t); + auto last = first + sizeof (t); + return { first, last }; + } + + + //------------------------------------------------------------------------- + template + view + make_byte_view (const T &&t) = delete; + + /////////////////////////////////////////////////////////////////////////// template < typename BeginA, typename EndA,