From 64f2735e603336363d55194c7717951af990313a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Jun 2022 14:10:58 +0200 Subject: [PATCH] util/SpanCast: add ToStringView() --- src/util/SpanCast.hxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/util/SpanCast.hxx b/src/util/SpanCast.hxx index 0ca95bc40..3aec5dfa4 100644 --- a/src/util/SpanCast.hxx +++ b/src/util/SpanCast.hxx @@ -85,3 +85,15 @@ AsBytes(std::string_view sv) noexcept { return std::as_bytes(ToSpan(sv)); } + +constexpr std::string_view +ToStringView(std::span s) noexcept +{ + return {s.data(), s.size()}; +} + +constexpr std::string_view +ToStringView(std::span s) noexcept +{ + return ToStringView(FromBytesStrict(s)); +}