mirror of
https://github.com/matrix-construct/construct
synced 2025-01-14 00:34:18 +01:00
ircd: Fix issues with byte_view conversions.
This commit is contained in:
parent
5ca5f4b405
commit
ddc0443edb
1 changed files with 10 additions and 10 deletions
|
@ -271,13 +271,16 @@ struct ircd::byte_view
|
|||
|
||||
operator const T &() const
|
||||
{
|
||||
if(unlikely(sizeof(T) > s.size()))
|
||||
throw std::bad_cast();
|
||||
|
||||
return *reinterpret_cast<const T *>(s.data());
|
||||
}
|
||||
|
||||
byte_view(const string_view &s = {})
|
||||
:s{s}
|
||||
{
|
||||
if(unlikely(sizeof(T) != s.size()))
|
||||
if(unlikely(sizeof(T) > s.size()))
|
||||
throw std::bad_cast();
|
||||
}
|
||||
|
||||
|
@ -291,25 +294,22 @@ struct ircd::byte_view
|
|||
///
|
||||
/// This is an important specialization to take note of. When you see
|
||||
/// byte_view<string_view> know that another type's bytes are being represented
|
||||
/// by the string_view.
|
||||
/// by the string_view if that type is not string_view family itself.
|
||||
template<>
|
||||
struct ircd::byte_view<ircd::string_view>
|
||||
:string_view
|
||||
{
|
||||
template<class T>
|
||||
template<class T,
|
||||
typename std::enable_if<!std::is_base_of<std::string_view, T>::value, int *>::type = nullptr>
|
||||
byte_view(const T &t)
|
||||
:string_view{reinterpret_cast<const char *>(&t), sizeof(T)}
|
||||
{}
|
||||
};
|
||||
|
||||
/// string_view -> string_view (completeness)
|
||||
namespace ircd
|
||||
{
|
||||
template<> inline
|
||||
byte_view<string_view>::byte_view(const string_view &t)
|
||||
/// string_view -> string_view (completeness)
|
||||
byte_view(const string_view &t)
|
||||
:string_view{t}
|
||||
{}
|
||||
}
|
||||
};
|
||||
|
||||
inline bool
|
||||
ircd::operator!(const string_view &str)
|
||||
|
|
Loading…
Reference in a new issue