util/SpanCast: allow ReferenceAsBytes() only with trivially-copyable

Addd the std::has_unique_object_representations_v constraint so we
cast stuff to std::byte only if this would make sense.
This commit is contained in:
Max Kellermann 2024-04-16 12:31:44 +02:00
parent 141f518bdd
commit fae235197f

View File

@ -64,6 +64,7 @@ AsBytes(std::string_view sv) noexcept
* Cast a reference to a fixed-size std::span<const std::byte>. * Cast a reference to a fixed-size std::span<const std::byte>.
*/ */
template<typename T> template<typename T>
requires std::has_unique_object_representations_v<T>
constexpr auto constexpr auto
ReferenceAsBytes(const T &value) noexcept ReferenceAsBytes(const T &value) noexcept
{ {
@ -71,6 +72,7 @@ ReferenceAsBytes(const T &value) noexcept
} }
template<typename T> template<typename T>
requires std::has_unique_object_representations_v<T>
constexpr auto constexpr auto
ReferenceAsWritableBytes(T &value) noexcept ReferenceAsWritableBytes(T &value) noexcept
{ {