std::formatter<std::thread::id>
來自 cppreference.com
定義於標頭檔案 <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) |
定義給定型別的格式化規則 (類模板) |