diff --git a/view.hpp b/view.hpp index 6c36e6aa..315bc718 100644 --- a/view.hpp +++ b/view.hpp @@ -565,39 +565,29 @@ namespace util { // // useful for passing in memory structures to file descriptors and the // like. but the consequences of endian conversion is on the user... - template - view + // + // we have to be careful that rval-references and other temporaries aren't + // accepted in this signature. + template < + typename ByteT = std::byte, + typename T + > + auto make_byte_view (T &t) { - auto first = reinterpret_cast (&t); - auto last = first + sizeof (t); - return { first, last }; + using cursor_type = std::conditional_t< + std::is_const_v, + ByteT const*, + ByteT* + >; + + return util::view { + reinterpret_cast (&t), + sizeof (T) + }; } - //------------------------------------------------------------------------- - 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,