std::formatter<std::thread::id>
Von cppreference.com
| Definiert in Header <thread> |
||
| template< class CharT > struct formatter<std::thread::id, CharT>; |
(seit C++23) | |
Die Template-Spezialisierung von std::formatter für die std::thread::id-Klasse ermöglicht es Benutzern, eine Thread-ID in ihre Textdarstellung mithilfe von Formatierungsfunktionen zu konvertieren.
Inhalt |
[edit] Format-Spezifikation
Die Syntax der Formatierungsspezifikationen lautet
| fill-and-align (optional) width (optional) | |||||||||
fill-and-align und width haben die gleiche Bedeutung wie in der Standard-Format-Spezifikation. Die Standardausrichtung ist >.
Die formatierte Ausgabe entspricht der Ausgabe von operator<<, entsprechend den Format-Spezifizierern angepasst.
[edit] Anmerkungen
| Feature-Test-Makro | Wert | Std | Feature |
|---|---|---|---|
__cpp_lib_formatters |
202302L |
(C++23) | Formatierung von std::thread::id und std::stacktrace |
[edit] Beispiel
Führen Sie diesen Code aus
#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); }
Mögliche Ausgabe
current thread id: 140046396632256 ====0=====
[edit] Siehe auch
| (C++20) |
definiert Formatierungsregeln für einen gegebenen Typ (Klassentemplate) |