From ab495bb0f7e191fd8aaace5f0ad496ca6cfba33d Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 30 Jul 2018 13:51:31 +1000 Subject: [PATCH] view: reduce ambiguity in make_byte_view --- view.hpp | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) 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,