From cppreference.com
template<classCharT>structformatter<std::thread::id,CharT>;(since C++23)The template specialization of
for the
class allows users to convert a thread identifier to its textual representation using
.
Format specification
The syntax of format specifications is:
fill-and-align(optional)width(optional)fill-and-align and width have the same meaning as in
. The default alignment is >.
The formatted output matches the output of
, adjusted as appropriate for the format specifiers.
Notes
macroValueStdFeature
(C++23)Formatting std::thread::id and std::stacktraceExample
Run this code
#include<format>#include<iostream>#include<thread>intmain(){std::thread::idthis_id=std::this_thread::get_id();std::thread::idnull_id;std::cout<<std::format("current thread id: {}\n",this_id);std::cout<<std::format("{:=^10}\n",null_id);}Possible output:
current thread id: 140046396632256 ====0===== See also
(C++20)
defines formatting rules for a given type
(class template)