0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-02 00:38:24 +02:00

ircd: Fix issues with byte_view conversions.

This commit is contained in:
Jason Volk 2017-10-15 21:20:02 -07:00
parent 5ca5f4b405
commit ddc0443edb

View file

@ -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)