命名空间
变体
操作

std::formatter<std::thread::id>

来自 cppreference.cn
< cpp‎ | thread‎ | thread‎ | id
 
 
并发支持库
线程
(C++11)
(C++20)
this_thread 命名空间
(C++11)
(C++11)
(C++11)
协作式取消
互斥
(C++11)
通用锁管理
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
条件变量
(C++11)
信号量
闩锁与屏障
(C++20)
(C++20)
期值
(C++11)
(C++11)
(C++11)
(C++11)
安全回收
(C++26)
Hazard 指针
原子类型
(C++11)
(C++20)
原子类型的初始化
(C++11)(在 C++20 中弃用)
(C++11)(在 C++20 中弃用)
内存排序
(C++11)(在 C++26 中弃用)
用于原子操作的自由函数
用于原子标志的自由函数
 
 
std::thread::id
成员函数
非成员函数
(直到 C++20)(直到 C++20)(直到 C++20)(直到 C++20)(直到 C++20)(C++20)
辅助类
formatter<std::thread::id>
(C++23)
 
定义于头文件 <thread>
template< class CharT >
struct formatter<std::thread::id, CharT>;
(自 C++23 起)

用于 std::formatter 的模板特化,针对 std::thread::id 类,允许用户使用格式化函数将线程标识符转换为其文本表示形式。

目录

[编辑] 格式规范

格式规范的语法是

填充与对齐(可选) 宽度(可选)

填充与对齐宽度 的含义与 标准格式规范 中相同。默认对齐方式为 >

格式化输出与 operator<< 的输出匹配,并根据格式说明符进行适当调整。

[编辑] 注释

特性测试 Std 特性
__cpp_lib_formatters 202302L (C++23) 格式化 std::thread::idstd::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)
定义给定类型的格式化规则
(类模板) [编辑]