output/snapcast/Client: work around clang 14 std::span cast bug
Closes https://github.com/MusicPlayerDaemon/MPD/issues/1538
This commit is contained in:
parent
843dad19e9
commit
f045cf43e4
|
@ -25,6 +25,7 @@
|
|||
#include "event/Loop.hxx"
|
||||
#include "net/SocketError.hxx"
|
||||
#include "net/UniqueSocketDescriptor.hxx"
|
||||
#include "util/SpanCast.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <cassert>
|
||||
|
@ -126,7 +127,7 @@ SendT(SocketDescriptor s, const T &buffer) noexcept
|
|||
static bool
|
||||
Send(SocketDescriptor s, std::string_view buffer) noexcept
|
||||
{
|
||||
return Send(s, std::as_bytes(std::span{buffer}));
|
||||
return Send(s, AsBytes(buffer));
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <span>
|
||||
#include <string_view>
|
||||
|
||||
/**
|
||||
* Cast a std::span<std::byte> to a std::span<T>, rounding down to the
|
||||
|
@ -47,3 +48,21 @@ FromBytesFloor(std::span<std::byte> other) noexcept
|
|||
other.size() / sizeof(T),
|
||||
};
|
||||
}
|
||||
|
||||
constexpr std::span<const char>
|
||||
ToSpan(std::string_view sv) noexcept
|
||||
{
|
||||
#if defined(__clang__) && __clang_major__ < 15
|
||||
/* workaround for old clang/libc++ versions which can't cast
|
||||
std::string_view to std::span */
|
||||
return {sv.data(), sv.size()};
|
||||
#else
|
||||
return std::span{sv};
|
||||
#endif
|
||||
}
|
||||
|
||||
inline std::span<const std::byte>
|
||||
AsBytes(std::string_view sv) noexcept
|
||||
{
|
||||
return std::as_bytes(ToSpan(sv));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue