◐ Shell
clean mode source ↗

src: fix MaybeStackBuffer char_traits deprecation warning · nodejs/node@cd9890a

Original file line numberDiff line numberDiff line change

@@ -390,6 +390,14 @@ constexpr size_t strsize(const T (&)[N]) {

390390

return N - 1;

391391

}

392392
393+

// A type that has a valid std::char_traits specialization, as required by

394+

// std::basic_string and std::basic_string_view.

395+

template <typename T>

396+

concept standard_char_type =

397+

std::is_same_v<T, char> || std::is_same_v<T, wchar_t> ||

398+

std::is_same_v<T, char8_t> || std::is_same_v<T, char16_t> ||

399+

std::is_same_v<T, char32_t>;

400+
393401

// Allocates an array of member type T. For up to kStackStorageSize items,

394402

// the stack is used, otherwise malloc().

395403

template <typename T, size_t kStackStorageSize = 1024>

@@ -503,8 +511,12 @@ class MaybeStackBuffer {

503511

free(buf_);

504512

}

505513
506-

inline std::basic_string<T> ToString() const { return {out(), length()}; }

507-

inline std::basic_string_view<T> ToStringView() const {

514+

template <standard_char_type U = T>

515+

inline std::basic_string<U> ToString() const {

516+

return {out(), length()};

517+

}

518+

template <standard_char_type U = T>

519+

inline std::basic_string_view<U> ToStringView() const {

508520

return {out(), length()};

509521

}

510522

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