util/SpanCast: add const support to FromBytesFloor()

This commit is contained in:
Max Kellermann 2022-06-01 21:40:13 +02:00
parent 04041f9583
commit bd96f6e572
1 changed files with 4 additions and 1 deletions

View File

@ -33,13 +33,16 @@
#include <span>
#include <string_view>
template<typename From, typename To>
using CopyConst = std::conditional_t<std::is_const_v<From>, const To, To>;
/**
* Cast a std::span<std::byte> to a std::span<T>, rounding down to the
* next multiple of T's size.
*/
template<typename T>
constexpr std::span<T>
FromBytesFloor(std::span<std::byte> other) noexcept
FromBytesFloor(std::span<CopyConst<T, std::byte>> other) noexcept
{
static_assert(sizeof(T) > 0, "Empty base type");