std::formatter<std::thread::id>
来自 cppreference.cn
定义于头文件 <thread> |
||
template< class CharT > struct formatter<std::thread::id, CharT>; |
(C++23 起) | |
std::formatter 对 std::thread::id 类的模板特化允许用户使用格式化函数将线程标识符转换为其文本表示。
目录 |
[编辑] 格式说明
格式规范的语法是
fill-and-align (可选) width (可选) | |||||||||
fill-and-align 和 width 的含义与标准格式说明中相同。默认对齐方式为 >
。
格式化输出与 operator<<
的输出匹配,并根据格式说明符进行适当调整。
[编辑] 注意
特性测试宏 | 值 | 标准 | 特性 |
---|---|---|---|
__cpp_lib_formatters |
202302L |
(C++23) | 格式化 std::thread::id 和 std::stacktrace |
[编辑] 示例
运行此代码
#include <format> #include <iostream> #include <thread> int main() { std::thread::id this_id = std::this_thread::get_id(); std::thread::id null_id; std::cout << std::format("current thread id: {}\n", this_id); std::cout << std::format("{:=^10}\n", null_id); }
可能的输出
current thread id: 140046396632256 ====0=====
[编辑] 参阅
(C++20) |
定义给定类型的格式化规则 (类模板) |