view: allow multibyte targets for make_byte_view

This commit is contained in:
Danny Robson 2018-12-19 17:13:47 +11:00
parent 072dce8891
commit f648ad9810

View File

@ -596,22 +596,17 @@ namespace cruft {
/// We have to be careful that rval-references and other temporaries aren't /// We have to be careful that rval-references and other temporaries aren't
/// accepted in this signature. /// accepted in this signature.
template < template <
typename WordT = std::byte, typename WordT = std::byte const,
typename T typename T
> >
auto cruft::view<WordT*>
make_byte_view (T &t) make_byte_view (T &t)
{ {
static_assert (sizeof (T) % sizeof (WordT) == 0); static_assert (sizeof (T) % sizeof (WordT) == 0);
static_assert (std::is_const_v<T> ? std::is_const_v<WordT> : true);
using cursor_type = std::conditional_t<
std::is_const_v<T>,
WordT const*,
WordT*
>;
return view { return view {
cast::alignment<cursor_type> (&t), cast::alignment<WordT*> (&t),
sizeof (T) / sizeof (WordT) sizeof (T) / sizeof (WordT)
}; };
} }