std::formatter<std::thread::id>
在标头
<thread> 定义 |
||
template< class CharT >
struct formatter<std::thread::id, CharT>; |
(C++23 起) | |
std::formatter 模板针对 std::thread::id 类的特化允许用户使用格式化函数将线程标识符转换为文本表示。
格式说明
格式说明的语法是:
填充与对齐 (可选) 宽度 (可选) | |||||||||
填充与对齐 和 宽度 与标准格式说明中的含义相同。默认对齐方式为 >
。
格式化后的输出结果与 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("当前线程 id: {}\n", this_id); std::cout << std::format("{:=^10}\n", null_id); }
可能的输出:
当前线程 id: 140046396632256 ====0=====
参阅
(C++20)
|
定义针对给定类型的格式化规则 (类模板) |