aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include/span.h
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee/include/span.h')
-rw-r--r--contrib/epee/include/span.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/contrib/epee/include/span.h b/contrib/epee/include/span.h
index 82936a777..bbd5d690c 100644
--- a/contrib/epee/include/span.h
+++ b/contrib/epee/include/span.h
@@ -147,6 +147,16 @@ namespace epee
return {reinterpret_cast<const std::uint8_t*>(src.data()), src.size_bytes()};
}
+ //! \return `span<std::uint8_t>` from a STL compatible `src`.
+ template<typename T>
+ constexpr span<std::uint8_t> to_mut_byte_span(T& src)
+ {
+ using value_type = typename T::value_type;
+ static_assert(!std::is_empty<value_type>(), "empty value types will not work -> sizeof == 1");
+ static_assert(!has_padding<value_type>(), "source value type may have padding");
+ return {reinterpret_cast<std::uint8_t*>(src.data()), src.size() * sizeof(value_type)};
+ }
+
//! \return `span<const std::uint8_t>` which represents the bytes at `&src`.
template<typename T>
span<const std::uint8_t> as_byte_span(const T& src) noexcept