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
17 changes: 15 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,15 @@ 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 +512,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()};
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be condensed into a single concept couldn't it? Just to avoid the duplication.

// This can only be used if the buffer contains path data in UTF8
Expand Down