diff options
author | Riccardo Spagni <ric@spagni.net> | 2019-01-16 19:04:22 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2019-01-16 19:04:22 +0200 |
commit | 846362842c9893cdbbea1dd1f00931c50bb2df5e (patch) | |
tree | c7e91557c2349a3cbeb23053950de96185428595 /contrib/epee/include/span.h | |
parent | Merge pull request #4973 (diff) | |
parent | epee: better network buffer data structure (diff) | |
download | monero-846362842c9893cdbbea1dd1f00931c50bb2df5e.tar.xz |
Merge pull request #4976
85665003 epee: better network buffer data structure (moneromooo-monero)
Diffstat (limited to 'contrib/epee/include/span.h')
-rw-r--r-- | contrib/epee/include/span.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/contrib/epee/include/span.h b/contrib/epee/include/span.h index b1296a0b7..cfb5b1a17 100644 --- a/contrib/epee/include/span.h +++ b/contrib/epee/include/span.h @@ -163,4 +163,12 @@ namespace epee static_assert(!has_padding<T>(), "source type may have padding"); return {reinterpret_cast<std::uint8_t*>(std::addressof(src)), sizeof(T)}; } + + //! make a span from a std::string + template<typename T> + span<const T> strspan(const std::string &s) noexcept + { + static_assert(std::is_same<T, char>() || std::is_same<T, unsigned char>() || std::is_same<T, int8_t>() || std::is_same<T, uint8_t>(), "Unexpected type"); + return {reinterpret_cast<const T*>(s.data()), s.size()}; + } } |