Libstdc++: Use __chrono_write for chrono ostream insertion.
Libstdc++ chrono output now uses a new helper function for improved formatting and buffer management.
The C++ standard library’s chrono formatting for operator<< has been refactored to use a new helper function, __detail::__chrono_write. This function formats chrono objects into a stack buffer using std::format_to_n and then writes the output via __ostream_insert. This change consolidates formatting logic, allows per-type buffer tuning via a _BufSize template parameter, and replaces older methods like std::format, std::vformat, and basic_stringstream for chrono output.
In Details
Libstdc++'s chrono I/O has been updated with the introduction of __detail::__chrono_write. This internal helper leverages std::format_to_n with _S_empty_fs() for efficient formatting into a stack buffer, controlled by a _BufSize non-type template parameter. The operator<< overloads for all chrono types now utilize this helper, abstracting away the underlying formatting and stream insertion mechanisms and improving buffer management by sizing it to the maximum expected output for each type.
- chrono
- The C++ standard library header for time utility facilities, providing types for durations, time points, and clocks.
- ostream insertion
- The process of writing data to an output stream, typically using the
operator<<overload. - std::format_to_n
- A C++20 formatting function that writes formatted output to a buffer and limits the number of characters written.
- stack buffer
- A temporary memory buffer allocated on the program's call stack, used for short-lived data.