From 60bd71a57b26691f9c620e40d109687944013a74 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 17 Dec 2018 14:45:09 +1100 Subject: [PATCH] view: allow multibyte casts in make_byte_view --- view.hpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/view.hpp b/view.hpp index 2d0c98d8..f2cfe63f 100644 --- a/view.hpp +++ b/view.hpp @@ -576,32 +576,31 @@ namespace cruft { /////////////////////////////////////////////////////////////////////////// - // 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... - // - // we have to be careful that rval-references and other temporaries aren't - // accepted in this signature. + /// Calculates a word 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... + /// + /// We have to be careful that rval-references and other temporaries aren't + /// accepted in this signature. template < - typename ByteT = std::byte, + typename WordT = std::byte, typename T > auto make_byte_view (T &t) { - static_assert (std::is_integral_v); - static_assert (sizeof (T) % sizeof (ByteT) == 0); + static_assert (sizeof (T) % sizeof (WordT) == 0); using cursor_type = std::conditional_t< std::is_const_v, - ByteT const*, - ByteT* + WordT const*, + WordT* >; return view { cast::alignment (&t), - sizeof (T) / sizeof (ByteT) + sizeof (T) / sizeof (WordT) }; }