view: reduce ambiguity in make_byte_view

This commit is contained in:
Danny Robson 2018-07-30 13:51:31 +10:00
parent 56ed44f0e3
commit ab495bb0f7

View File

@ -565,39 +565,29 @@ namespace util {
// //
// useful for passing in memory structures to file descriptors and the // useful for passing in memory structures to file descriptors and the
// like. but the consequences of endian conversion is on the user... // like. but the consequences of endian conversion is on the user...
template <typename ByteT = std::byte, typename T> //
view<ByteT*> // 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) make_byte_view (T &t)
{ {
auto first = reinterpret_cast<ByteT*> (&t); using cursor_type = std::conditional_t<
auto last = first + sizeof (t); std::is_const_v<T>,
return { first, last }; ByteT const*,
ByteT*
>;
return util::view {
reinterpret_cast<cursor_type> (&t),
sizeof (T)
};
} }
//-------------------------------------------------------------------------
template <typename T>
view<std::byte*>
make_byte_view (T&&) = delete;
//-------------------------------------------------------------------------
template <typename ByteT = std::byte, typename T>
view<const ByteT*>
make_byte_view (const T &t)
{
auto first = reinterpret_cast<ByteT const*> (&t);
auto last = first + sizeof (t);
return { first, last };
}
//-------------------------------------------------------------------------
template <typename T>
view<const std::byte*>
make_byte_view (const T &&t) = delete;
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
template < template <
typename BeginA, typename EndA, typename BeginA, typename EndA,