Skip to content

Commit

Permalink
util/SpanCast: rewrite ToStringView(std::span<std::byte>) to avoid ca…
Browse files Browse the repository at this point in the history
…st ambiguities
  • Loading branch information
MaxKellermann committed Jul 23, 2024
1 parent be8ba91 commit 5b038b6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/util/SpanCast.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,15 @@ ToStringView(std::span<T> s) noexcept
{
return {s.data(), s.size()};
}

/* this overload matches std::span<std::byte> (without "const") and is
written that way to avoid ambiguities when passing an object that
has cast operators for both std::span<std::byte> and
std::span<const std::byte> */
template<typename T>
constexpr std::string_view
ToStringView(std::span<T> s) noexcept
requires(std::is_same_v<std::remove_const_t<T>, std::byte>)
{
return ToStringView(FromBytesStrict<const char>(s));
}

0 comments on commit 5b038b6

Please sign in to comment.