Libstdc++: Format all contiguous ranges using span
Libstdc++ now formats all contiguous ranges as spans, enabling non-locking formatter optimization.
Libstdc++ now formats all contiguous ranges as a span of possibly-const qualified _Tp. This change enables the _M_format<const span<T>> specialization, which is already used by formatter specializations for ranges. By using raw pointers to iterate during formatting, no stdio lock is taken, enabling enable_nonlocking_formatter_optimization for all contiguous ranges.
In Details
This commit modifies the range_formatter::format function in <std/format> to treat all contiguous ranges as span<__format::__maybe_const<_Tp, _CharT>>. This allows the use of the existing formatter specialization for ranges (_M_format<const span<T>>). By iterating with raw pointers, the code avoids taking stdio locks which would otherwise block enabling enable_nonlocking_formatter_optimization. Toolchain engineers should examine the implications for custom iterators and the interaction with std::format.
For Context
The C++ standard library's std::format provides a way to format data into strings. This commit optimizes the formatting of contiguous ranges (like arrays or vectors) by treating them as span objects. A span provides a lightweight view of a contiguous sequence of elements. By using span and raw pointers, the formatting process can avoid taking locks, leading to faster and more efficient string formatting.