Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ constexpr size_t strsize(const T (&)[N]) {
return N - 1;
}

// A type that has a valid std::char_traits specialization, as required by
// std::basic_string and std::basic_string_view.
template <typename T>
concept standard_char_type =
std::is_same_v<T, char> || std::is_same_v<T, wchar_t> ||
std::is_same_v<T, char8_t> || std::is_same_v<T, char16_t> ||
std::is_same_v<T, char32_t>;

// Allocates an array of member type T. For up to kStackStorageSize items,
// the stack is used, otherwise malloc().
template <typename T, size_t kStackStorageSize = 1024>
Expand Down Expand Up @@ -503,8 +511,12 @@ class MaybeStackBuffer {
free(buf_);
}

inline std::basic_string<T> ToString() const { return {out(), length()}; }
inline std::basic_string_view<T> ToStringView() const {
template <standard_char_type U = T>
inline std::basic_string<U> ToString() const {
return {out(), length()};
}
template <standard_char_type U = T>
inline std::basic_string_view<U> ToStringView() const {
return {out(), length()};
}
// This can only be used if the buffer contains path data in UTF8
Expand Down
Loading