util/SpanCast: add const support to FromBytesFloor()
This commit is contained in:
parent
04041f9583
commit
bd96f6e572
@ -33,13 +33,16 @@
|
|||||||
#include <span>
|
#include <span>
|
||||||
#include <string_view>
|
#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
|
* Cast a std::span<std::byte> to a std::span<T>, rounding down to the
|
||||||
* next multiple of T's size.
|
* next multiple of T's size.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
constexpr std::span<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");
|
static_assert(sizeof(T) > 0, "Empty base type");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user