mu-utils: add to_string_view

This commit is contained in:
Dirk-Jan C. Binnema 2023-09-19 23:43:15 +03:00
parent 8ba153067b
commit 6ce94ce914
1 changed files with 13 additions and 0 deletions

View File

@ -425,6 +425,19 @@ to_string(const T& val)
return sstr.str();
}
/**
* Convert to std::string to a std::string_view
* Careful with the lifetimes!
*
* @param s a string
*
* @return a string_view
*/
static inline std::string_view
to_string_view(const std::string& s)
{
return std::string_view{s.data(), s.size()};
}
/**
* Consume a gchar and return a std::string