From 5b038b6335f4c2342ce3599f8ca28d7204a545f3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 23 Jul 2024 13:20:40 +0200 Subject: [PATCH] util/SpanCast: rewrite ToStringView(std::span) to avoid cast ambiguities --- src/util/SpanCast.hxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/util/SpanCast.hxx b/src/util/SpanCast.hxx index 04817f9..59ea8bc 100644 --- a/src/util/SpanCast.hxx +++ b/src/util/SpanCast.hxx @@ -98,3 +98,15 @@ ToStringView(std::span s) noexcept { return {s.data(), s.size()}; } + +/* this overload matches std::span (without "const") and is + written that way to avoid ambiguities when passing an object that + has cast operators for both std::span and + std::span */ +template +constexpr std::string_view +ToStringView(std::span s) noexcept + requires(std::is_same_v, std::byte>) +{ + return ToStringView(FromBytesStrict(s)); +}