1#ifndef TOPAZ_CORE_MEMORY_HPP
2#define TOPAZ_CORE_MEMORY_HPP
10 constexpr auto view_bytes(T&& t) -> std::conditional_t<std::is_const_v<T>, std::span<const std::byte>, std::span<std::byte>>
12 if constexpr(
requires{std::ranges::contiguous_range<T>;})
15 using V = std::ranges::range_value_t<T>;
16 std::span<V> range{std::begin(t), std::end(t)};
17 if constexpr(std::is_const_v<V>)
19 return std::as_bytes(range);
23 return std::as_writable_bytes(range);
29 static_assert(std::is_standard_layout_v<T>,
"view_bytes must be provided a contiguous range or a standard-layout-type. You have provided neither.");
31 std::span<T, 1> span{&t};
32 if constexpr(std::is_const_v<T>)
34 return std::as_bytes(span);
38 return std::as_writable_bytes(span);