diff --git a/include/ircd/string_view.h b/include/ircd/string_view.h index 7902fe684..cd1e4494c 100644 --- a/include/ircd/string_view.h +++ b/include/ircd/string_view.h @@ -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(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 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 :string_view { - template + template::value, int *>::type = nullptr> byte_view(const T &t) :string_view{reinterpret_cast(&t), sizeof(T)} {} -}; -/// string_view -> string_view (completeness) -namespace ircd -{ - template<> inline - byte_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)