[libcxx-commits] [libcxx] [libc++] Use std::to_chars to format thread::id and canonicalize the representation across platforms (PR #181624)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Mar 9 03:35:55 PDT 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 =
----------------
philnik777 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<<`.
Where? I definitely didn't mean to imply that.
> 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<<`?
We never tested the exact output of `operator<<` because it's not specified by the standard. I guess we can add a libc++-specific test to show that it's the same on all platforms now.
https://github.com/llvm/llvm-project/pull/181624
More information about the libcxx-commits
mailing list