The <format>
header patch series
A short write-up with some additional information of the current <format>
patch series in review. This explains the goals and non-goals of the series.
The first part describes the current series, the second part the future plans.
Current patch series
This patch series1 implements the first part of the <format>
header. The
features implemented are:
- All format functions, including locale support.
- Formatters for:
- strings, including Unicode support.
- integers, there’s an extension for 128-bit integers, but that’s partly done.
- chars
- booleans
- floating-point, only a stub.
The implementation hasn’t been optimized for speed nor for code size. This means the code isn’t intended to be ABI stable. Some of these optimizations are required to be Standard compliant. The committee will probably approve another ABI breaking change for C++20; P2216. This means the code isn’t available on the Apple platform since it requires ABI stability2.
The following parts haven’t been implemented yet:
- Formatters for:
- pointers
- floating-point: This still requires me to finish
std::to_chars
for floating-point values. - handle class: This allows user defined formatters. These formatters may
inherit from
std::formatter<T>
. Sincestd::formatter<T>
isn’t ABI it’s a bad idea to increase the effects of an ABI break.
<chrono>
support.
Note: At the moment clang-format doesn’t work well with concepts. Therefore not all code has been formatted properly. Most code still sticks to an 80-column limit. This can be fixed after the series has landed. Fixing that now has only a small benefit, but will probably result in merge conflicts.
Note: The patch series doesn’t implement the correct module mapping. At the moment there’s no CI pipeline to test the modular build. D103559 implements this pipeline. After it lands the series will be rebased and the module mapping will be implemented.
The hope is to get these changes shipped in libc++13.
Future plans
Assuming P2216 will be approved and backported to C++20 during the June 2021 meeting the next steps will be:
- Optimize code size and performance:
- Implement P2216,
- Implement improvements suggested and mandated by the Standard,
- Implement other improvements marked with
TODO FMT
.
- Implement missing formatters:
- pointers,
- handle class.
After these changes the libc++ ABI should be stable. These features are planned for libc++14. It would be great to get them in libc++13, but that’s unlikely to happen.
The next steps are:
- Finish floating-point formatting.
- Fully implement 128-bit integral support.
- Address all
TODO FMT
comments. - Enable the feature macro
__lib_cpp_format
.
At this point the formatting (except <chrono>
) is complete. However there
might be new papers and LWG-issues to implement. For example, P1636,
P2093, and P2286 might have landed in the C++23 draft.
The hope is to get this done before libc++14.
At this point focus will move to <chrono>
, however the author hasn’t checked
the current C++20 implementation status of <chrono>
.