Follow-up to #1741 / #1742.
Several APIs still carry multiple overloads for different string types. Now that the library requires C++17, we can modernize by preferring std::string_view and removing the redundant UTF-8 overloads, replacing them with a single constrained template, as a semver-major change.
For String::New, Symbol::New, and Symbol::For, collapse the const std::string& + std::string_view pair into:
template <typename T,
std::enable_if_t<
std::is_convertible_v<const T&, std::string_view> &&
!std::is_convertible_v<const T&, const char*>, int> = 0>
static String New(napi_env env, const T& t);
This matches the C++17 standard-library idiom (std::string's find/append/compare/… members). The !is_convertible_v<const T&, const char*> clause keeps const char* and literals on the dedicated overload and filters nullptr (avoiding a UB string_view(nullptr)).
The enable_if alias is shareable across APIs e.g. enable_if_string_view_like_t<T>.
Follow-up to #1741 / #1742.
Several APIs still carry multiple overloads for different string types. Now that the library requires C++17, we can modernize by preferring
std::string_viewand removing the redundant UTF-8 overloads, replacing them with a single constrained template, as a semver-major change.For
String::New,Symbol::New, andSymbol::For, collapse theconst std::string&+std::string_viewpair into:This matches the C++17 standard-library idiom (
std::string's find/append/compare/… members). The!is_convertible_v<const T&, const char*>clause keepsconst char*and literals on the dedicated overload and filtersnullptr(avoiding a UBstring_view(nullptr)).The
enable_ifalias is shareable across APIs e.g.enable_if_string_view_like_t<T>.