aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include/span.h
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-12-06 18:04:33 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-12-23 16:46:07 +0000
commit85665003a7d9e013b1d7df5578dbf47ddf81b236 (patch)
treee5a3497f5ace88b3a671e4068d7e5d3a432b77f6 /contrib/epee/include/span.h
parentMerge pull request #4927 (diff)
downloadmonero-85665003a7d9e013b1d7df5578dbf47ddf81b236.tar.xz
epee: better network buffer data structure
avoids pointless allocs and memcpy
Diffstat (limited to 'contrib/epee/include/span.h')
-rw-r--r--contrib/epee/include/span.h8
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()};
+ }
}