[libcxx-commits] [libcxx] [libc++] Use std::to_chars to format thread::id and canonicalize the representation across platforms (PR #181624)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Mar 6 09:59:28 PST 2026
================
@@ -147,10 +147,15 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id) {
// use a temporary stream instead and just output the thread
// id representation as a string.
- basic_ostringstream<_CharT, _Traits> __sstr;
- __sstr.imbue(locale::classic());
- __sstr << __id.__id_;
- return __os << __sstr.str();
+ using __int_type = __conditional_t<is_pointer<__libcpp_thread_id>::value, uintptr_t, __libcpp_thread_id>;
+
+ static const size_t __buffer_size = numeric_limits<__int_type>::digits10 + 1;
+ char __buffer[__buffer_size];
+ auto __ret =
----------------
ldionne wrote:
I am a bit confused now: the PR description seems to imply that we're only changing the result of `std::format(...)` for a `thread::id`, but we're also changing the result of `operator<<`.
So this PR is really modifying both the result of `operator<<` and `std::format` for `thread::id`, keeping them in sync, but changing from the status quo. If I got that right, why is there no change to the tests for `operator<<`?
https://github.com/llvm/llvm-project/pull/181624
More information about the libcxx-commits
mailing list