[libcxx-commits] [libcxx] WIP - [libc++][string] P2587R3: `to_string` or not `to_string` (PR #78100)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jul 25 05:49:08 PDT 2024
================
@@ -247,6 +248,36 @@ long double stold(const wstring& str, size_t* idx) { return as_float<long double
// to_string
+#if _LIBCPP_STD_VER >= 26
+
+string to_string(int val) { return std::format("{}", val); }
+string to_string(long val) { return std::format("{}", val); }
+string to_string(long long val) { return std::format("{}", val); }
+string to_string(unsigned val) { return std::format("{}", val); }
+string to_string(unsigned long val) { return std::format("{}", val); }
+string to_string(unsigned long long val) { return std::format("{}", val); }
+
+# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
+wstring to_wstring(int val) { return std::format(L"{}", val); }
+wstring to_wstring(long val) { return std::format(L"{}", val); }
+wstring to_wstring(long long val) { return std::format(L"{}", val); }
+wstring to_wstring(unsigned val) { return std::format(L"{}", val); }
+wstring to_wstring(unsigned long val) { return std::format(L"{}", val); }
+wstring to_wstring(unsigned long long val) { return std::format(L"{}", val); }
+# endif
----------------
frederick-vs-ja wrote:
I believe overloads for integer types shouldn't be changed. They are efficient enough and already meeting the C++26 requirements (not accessing C locale) since commit 141c2b768db09569cfa227bd258be41593ba206d. And IIUC using `std::format` here will be a bit perssimizing.
https://github.com/llvm/llvm-project/pull/78100
More information about the libcxx-commits
mailing list