util/SpanCast: add FromBytesStrict()
This commit is contained in:
parent
bd96f6e572
commit
db03db0dca
|
@ -29,6 +29,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
|
@ -52,6 +53,18 @@ FromBytesFloor(std::span<CopyConst<T, std::byte>> other) noexcept
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Like FromBytesFloor(), but assert that rounding is not necessary.
|
||||
*/
|
||||
template<typename T>
|
||||
constexpr std::span<T>
|
||||
FromBytesStrict(std::span<CopyConst<T, std::byte>> other) noexcept
|
||||
{
|
||||
assert(other.size() % sizeof(T) == 0);
|
||||
|
||||
return FromBytesFloor<T>(other);
|
||||
}
|
||||
|
||||
constexpr std::span<const char>
|
||||
ToSpan(std::string_view sv) noexcept
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue