This changes the implementation of the formatter. Instead of inheriting
from a specialized parser all formatters will use the same generic
parser. This reduces the binary size.
The new parser contains some additional fields only used in the chrono
formatting. Since this doesn't change the size of the parser the fields
are in the generic parser. The parser is designed to fit in 128-bit,
making it cheap to pass by value.
The new format function is a const member function. This isn't required
by the Standard yet, but it will be after LWG-3636 is accepted.
Additionally P2286 adds a formattable concept which requires the member
function to be const qualified in C++23. This paper is likely to be
accepted in the 2022 July plenary.
Depends on D121530
NOTE parts of the code now contains duplicates for the current and new parser.
The intention is to remove the duplication in followup patches. A general
overview of the final code is available in D124620. That review however lacks a
bit of polish.
Most of the new code is based on the same algorithms used in the current code.
The final version of this code reduces the binary size by 17 KB for this example
code
int main() { { std::string_view sv{"hello world"}; std::format("{}{}|{}{}{}{}{}{}|{}{}{}{}{}{}|{}{}{}|{}{}|{}", true, '*', (signed char)(42), (short)(42), (int)(42), (long)(42), (long long)(42), (__int128_t)(42), (unsigned char)(42), (unsigned short)(42), (unsigned int)(42), (unsigned long)(42), (unsigned long long)(42), (__uint128_t)(42), (float)(42), (double)(42), (long double)(42), "hello world", sv, nullptr); } { std::wstring_view sv{L"hello world"}; std::format(L"{}{}|{}{}{}{}{}{}|{}{}{}{}{}{}|{}{}{}|{}{}|{}", true, L'*', (signed char)(42), (short)(42), (int)(42), (long)(42), (long long)(42), (__int128_t)(42), (unsigned char)(42), (unsigned short)(42), (unsigned int)(42), (unsigned long)(42), (unsigned long long)(42), (__uint128_t)(42), (float)(42), (double)(42), (long double)(42), L"hello world", sv, nullptr); } }
This will be done after all formatters are converted to this style.