C++ Format v8.1.0 Release Notes

Release Date: 2022-01-02 // 11 months ago
    • โšก๏ธ Optimized chrono formatting (#2500 <https://github.com/fmtlib/fmt/pull/2500>, #2537 <https://github.com/fmtlib/fmt/pull/2537>, #2541 <https://github.com/fmtlib/fmt/issues/2541>, #2544 <https://github.com/fmtlib/fmt/pull/2544>, #2550 <https://github.com/fmtlib/fmt/pull/2550>, #2551 <https://github.com/fmtlib/fmt/pull/2551>, #2576 <https://github.com/fmtlib/fmt/pull/2576>, #2577 <https://github.com/fmtlib/fmt/issues/2577>, #2586 <https://github.com/fmtlib/fmt/pull/2586>, #2591 <https://github.com/fmtlib/fmt/pull/2591>, #2594 <https://github.com/fmtlib/fmt/pull/2594>, #2602 <https://github.com/fmtlib/fmt/pull/2602>, #2617 <https://github.com/fmtlib/fmt/pull/2617>, #2628 <https://github.com/fmtlib/fmt/issues/2628>, #2633 <https://github.com/fmtlib/fmt/pull/2633>, #2670 <https://github.com/fmtlib/fmt/issues/2670>, #2671 <https://github.com/fmtlib/fmt/pull/2671>_).

    Processing of some specifiers such as %z and %Y is now up to 10-20 times faster, for example on GCC 11 with libstdc++::

    ----------------------------------------------------------------------------
    Benchmark                                  Before             After
    ----------------------------------------------------------------------------
    FMTFormatter_z                             261 ns             26.3 ns
    FMTFormatterCompile_z                      246 ns             11.6 ns
    FMTFormatter_Y                             263 ns             26.1 ns
    FMTFormatterCompile_Y                      244 ns             10.5 ns
    ----------------------------------------------------------------------------
    

    Thanks @phprus (Vladislav Shchapov) <https://github.com/phprus>_ and @toughengineer (Pavel Novikov) <https://github.com/toughengineer>_.

    • Implemented subsecond formatting for chrono durations (#2623 <https://github.com/fmtlib/fmt/pull/2623>). For example (godbolt <https://godbolt.org/z/es7vWTETe>_):

    .. code:: c++

     #include <fmt/chrono.h>
    
     int main() {
       fmt::print("{:%S}", std::chrono::milliseconds(1234));
     }
    

    prints "01.234".

    Thanks @matrackif <https://github.com/matrackif>_.

    • ๐Ÿ›  Fixed handling of precision 0 when formatting chrono durations (#2587 <https://github.com/fmtlib/fmt/issues/2587>, #2588 <https://github.com/fmtlib/fmt/pull/2588>). Thanks @lukester1975 <https://github.com/lukester1975>_.

    • ๐Ÿ›  Fixed an overflow on invalid inputs in the tm formatter (#2564 <https://github.com/fmtlib/fmt/pull/2564>). Thanks @phprus (Vladislav Shchapov) <https://github.com/phprus>.

    • โž• Added fmt::group_digits that formats integers with a non-localized digit separator (comma) for groups of three digits. For example (godbolt <https://godbolt.org/z/TxGxG9Poq>__):

    .. code:: c++

     #include <fmt/format.h>
    
     int main() {
       fmt::print("{} dollars", fmt::group_digits(1000000));
     }
    

    prints "1,000,000 dollars".

    • โž• Added support for faint, conceal, reverse and blink text styles (#2394 <https://github.com/fmtlib/fmt/pull/2394>_):

    https://user-images.githubusercontent.com/576385/147710227-c68f5317-f8fa-42c3-9123-7c4ba3c398cb.mp4

    Thanks @benit8 (Benoรฎt Lormeau) <https://github.com/benit8>_ and @data-man (Dmitry Atamanov) <https://github.com/data-man>_.

    • โž• Added experimental support for compile-time floating point formatting (#2426 <https://github.com/fmtlib/fmt/pull/2426>, #2470 <https://github.com/fmtlib/fmt/pull/2470>). It is currently limited to the header-only mode. Thanks @alexezeder (Alexey Ochapov) <https://github.com/alexezeder>_.

    • โž• Added UDL-based named argument support to compile-time format string checks (#2640 <https://github.com/fmtlib/fmt/issues/2640>, #2649 <https://github.com/fmtlib/fmt/pull/2649>). For example (godbolt <https://godbolt.org/z/ohGbbvonv>__):

    .. code:: c++

     #include <fmt/format.h>
    
     int main() {
       using namespace fmt::literals;
       fmt::print("{answer:s}", "answer"_a=42);
     }
    

    gives a compile-time error on compilers with C++20 consteval and non-type template parameter support (gcc 10+) because s is not a valid format specifier for an integer.

    Thanks @alexezeder (Alexey Ochapov) <https://github.com/alexezeder>_.

    • Implemented escaping of string range elements. For example (godbolt <https://godbolt.org/z/rKvM1vKf3>__):

    .. code:: c++

     #include <fmt/ranges.h>
     #include <vector>
    
     int main() {
       fmt::print("{}", std::vector<std::string>{"\naan"});
     }
    

    is now printed as::

    ["\naan"]
    

    instead of::

    ["
    aan"]
    
    • โž• Added an experimental ? specifier for escaping strings. (#2674 <https://github.com/fmtlib/fmt/pull/2674>). Thanks @BRevzin (Barry Revzin) <https://github.com/BRevzin>.

    • Switched to JSON-like representation of maps and sets for consistency with Python's str.format. For example (godbolt <https://godbolt.org/z/seKjoY9W5>__):

    .. code:: c++

     #include <fmt/ranges.h>
     #include <map>
    
     int main() {
       fmt::print("{}", std::map<std::string, int>{{"answer", 42}});
     }
    

    is now printed as::

    {"answer": 42}
    
    • ๐Ÿ‘ Extended fmt::join to support C++20-only ranges (#2549 <https://github.com/fmtlib/fmt/pull/2549>). Thanks @BRevzin (Barry Revzin) <https://github.com/BRevzin>.

    • โšก๏ธ Optimized handling of non-const-iterable ranges and implemented initial support for non-const-formattable types.

    • Disabled implicit conversions of scoped enums to integers that was accidentally introduced in earlier versions (#1841 <https://github.com/fmtlib/fmt/pull/1841>_).

    • ๐Ÿ—„ Deprecated implicit conversion of [const] signed char* and [const] unsigned char* to C strings.

    • ๐Ÿ—„ Deprecated _format, a legacy UDL-based format API (#2646 <https://github.com/fmtlib/fmt/pull/2646>). Thanks @alexezeder (Alexey Ochapov) <https://github.com/alexezeder>.

    • Marked format, formatted_size and to_string as [[nodiscard]] (#2612 <https://github.com/fmtlib/fmt/pull/2612>). @0x8000-0000 (Florin Iucha) <https://github.com/0x8000-0000>.

    • โž• Added missing diagnostic when trying to format function and member pointers as well as objects convertible to pointers which is explicitly disallowed (#2598 <https://github.com/fmtlib/fmt/issues/2598>, #2609 <https://github.com/fmtlib/fmt/pull/2609>, #2610 <https://github.com/fmtlib/fmt/pull/2610>). Thanks @AlexGuteniev (Alex Guteniev) <https://github.com/AlexGuteniev>.

    • Optimized writing to a contiguous buffer with format_to_n (#2489 <https://github.com/fmtlib/fmt/pull/2489>). Thanks @Roman-Koshelev <https://github.com/Roman-Koshelev>.

    • โšก๏ธ Optimized writing to non-char buffers (#2477 <https://github.com/fmtlib/fmt/pull/2477>). Thanks @Roman-Koshelev <https://github.com/Roman-Koshelev>.

    • Decimal point is now localized when using the L specifier.

    • ๐Ÿ‘Œ Improved floating point formatter implementation (#2498 <https://github.com/fmtlib/fmt/pull/2498>, #2499 <https://github.com/fmtlib/fmt/pull/2499>). Thanks @Roman-Koshelev <https://github.com/Roman-Koshelev>_.

    • ๐Ÿ›  Fixed handling of very large precision in fixed format (#2616 <https://github.com/fmtlib/fmt/pull/2616>_).

    • Made a table of cached powers used in FP formatting static (#2509 <https://github.com/fmtlib/fmt/pull/2509>). Thanks @jk-jeon (Junekey Jeon) <https://github.com/jk-jeon>.

    • Resolved a lookup ambiguity with C++20 format-related functions due to ADL (#2639 <https://github.com/fmtlib/fmt/issues/2639>, #2641 <https://github.com/fmtlib/fmt/pull/2641>). Thanks @mkurdej (Marek Kurdej) <https://github.com/mkurdej>_.

    • โœ‚ Removed unnecessary inline namespace qualification (#2642 <https://github.com/fmtlib/fmt/issues/2642>, #2643 <https://github.com/fmtlib/fmt/pull/2643>). Thanks @mkurdej (Marek Kurdej) <https://github.com/mkurdej>_.

    • Implemented argument forwarding in format_to_n (#2462 <https://github.com/fmtlib/fmt/issues/2462>, #2463 <https://github.com/fmtlib/fmt/pull/2463>). Thanks @owent (WenTao Ou) <https://github.com/owent>_.

    • ๐Ÿ›  Fixed handling of implicit conversions in fmt::to_string and format string compilation (#2565 <https://github.com/fmtlib/fmt/issues/2565>_).

    • ๐Ÿ”„ Changed the default access mode of files created by fmt::output_file to -rw-r--r-- for consistency with fopen (#2530 <https://github.com/fmtlib/fmt/issues/2530>_).

    • ๐Ÿ‘‰ Make fmt::ostream::flush public (#2435 <https://github.com/fmtlib/fmt/issues/2435>_).

    • ๐Ÿ‘Œ Improved C++14/17 attribute detection (#2615 <https://github.com/fmtlib/fmt/pull/2615>). Thanks @AlexGuteniev (Alex Guteniev) <https://github.com/AlexGuteniev>.

    • ๐Ÿ‘Œ Improved consteval detection for MSVC (#2559 <https://github.com/fmtlib/fmt/pull/2559>). Thanks @DanielaE (Daniela Engert) <https://github.com/DanielaE>.

    • ๐Ÿ‘Œ Improved documentation (#2406 <https://github.com/fmtlib/fmt/issues/2406>, #2446 <https://github.com/fmtlib/fmt/pull/2446>, #2493 <https://github.com/fmtlib/fmt/issues/2493>, #2513 <https://github.com/fmtlib/fmt/issues/2513>, #2515 <https://github.com/fmtlib/fmt/pull/2515>, #2522 <https://github.com/fmtlib/fmt/issues/2522>, #2562 <https://github.com/fmtlib/fmt/pull/2562>, #2575 <https://github.com/fmtlib/fmt/pull/2575>, #2606 <https://github.com/fmtlib/fmt/pull/2606>, #2620 <https://github.com/fmtlib/fmt/pull/2620>, #2676 <https://github.com/fmtlib/fmt/issues/2676>). Thanks @sobolevn (Nikita Sobolev) <https://github.com/sobolevn>, @UnePierre (Max FERGER) <https://github.com/UnePierre>, @zhsj <https://github.com/zhsj>, @phprus (Vladislav Shchapov) <https://github.com/phprus>, @ericcurtin (Eric Curtin) <https://github.com/ericcurtin>, @Lounarok <https://github.com/Lounarok>_.

    • ๐Ÿ‘Œ Improved fuzzers and added a fuzzer for chrono timepoint formatting (#2461 <https://github.com/fmtlib/fmt/pull/2461>, #2469 <https://github.com/fmtlib/fmt/pull/2469>). @pauldreik (Paul Dreik) <https://github.com/pauldreik>_,

    • Added the FMT_SYSTEM_HEADERS CMake option setting which marks {fmt}'s headers as system. It can be used to suppress warnings (#2644 <https://github.com/fmtlib/fmt/issues/2644>, #2651 <https://github.com/fmtlib/fmt/pull/2651>). Thanks @alexezeder (Alexey Ochapov) <https://github.com/alexezeder>_.

    • โž• Added the Bazel build system support (#2505 <https://github.com/fmtlib/fmt/pull/2505>, #2516 <https://github.com/fmtlib/fmt/pull/2516>). Thanks @Vertexwahn <https://github.com/Vertexwahn>_.

    • ๐Ÿ‘Œ Improved build configuration and tests (#2437 <https://github.com/fmtlib/fmt/issues/2437>, #2558 <https://github.com/fmtlib/fmt/pull/2558>, #2648 <https://github.com/fmtlib/fmt/pull/2648>, #2650 <https://github.com/fmtlib/fmt/pull/2650>, #2663 <https://github.com/fmtlib/fmt/pull/2663>, #2677 <https://github.com/fmtlib/fmt/pull/2677>). Thanks @DanielaE (Daniela Engert) <https://github.com/DanielaE>, @alexezeder (Alexey Ochapov) <https://github.com/alexezeder>, @phprus (Vladislav Shchapov) <https://github.com/phprus>_.

    • ๐Ÿ›  Fixed various warnings and compilation issues (#2353 <https://github.com/fmtlib/fmt/pull/2353>, #2356 <https://github.com/fmtlib/fmt/pull/2356>, #2399 <https://github.com/fmtlib/fmt/pull/2399>, #2408 <https://github.com/fmtlib/fmt/issues/2408>, #2414 <https://github.com/fmtlib/fmt/pull/2414>, #2427 <https://github.com/fmtlib/fmt/pull/2427>, #2432 <https://github.com/fmtlib/fmt/pull/2432>, #2442 <https://github.com/fmtlib/fmt/pull/2442>, #2434 <https://github.com/fmtlib/fmt/pull/2434>, #2439 <https://github.com/fmtlib/fmt/issues/2439>, #2447 <https://github.com/fmtlib/fmt/pull/2447>, #2450 <https://github.com/fmtlib/fmt/pull/2450>, #2455 <https://github.com/fmtlib/fmt/issues/2455>, #2465 <https://github.com/fmtlib/fmt/issues/2465>, #2472 <https://github.com/fmtlib/fmt/issues/2472>, #2474 <https://github.com/fmtlib/fmt/issues/2474>, #2476 <https://github.com/fmtlib/fmt/pull/2476>, #2478 <https://github.com/fmtlib/fmt/issues/2478>, #2479 <https://github.com/fmtlib/fmt/issues/2479>, #2481 <https://github.com/fmtlib/fmt/issues/2481>, #2482 <https://github.com/fmtlib/fmt/pull/2482>, #2483 <https://github.com/fmtlib/fmt/pull/2483>, #2490 <https://github.com/fmtlib/fmt/issues/2490>, #2491 <https://github.com/fmtlib/fmt/pull/2491>, #2510 <https://github.com/fmtlib/fmt/pull/2510>, #2518 <https://github.com/fmtlib/fmt/pull/2518>, #2528 <https://github.com/fmtlib/fmt/issues/2528>, #2529 <https://github.com/fmtlib/fmt/pull/2529>, #2539 <https://github.com/fmtlib/fmt/pull/2539>, #2540 <https://github.com/fmtlib/fmt/issues/2540>, #2545 <https://github.com/fmtlib/fmt/pull/2545>, #2555 <https://github.com/fmtlib/fmt/pull/2555>, #2557 <https://github.com/fmtlib/fmt/issues/2557>, #2570 <https://github.com/fmtlib/fmt/issues/2570>, #2573 <https://github.com/fmtlib/fmt/pull/2573>, #2582 <https://github.com/fmtlib/fmt/pull/2582>, #2605 <https://github.com/fmtlib/fmt/issues/2605>, #2611 <https://github.com/fmtlib/fmt/pull/2611>, #2647 <https://github.com/fmtlib/fmt/pull/2647>, #2627 <https://github.com/fmtlib/fmt/issues/2627>, #2630 <https://github.com/fmtlib/fmt/pull/2630>, #2635 <https://github.com/fmtlib/fmt/issues/2635>, #2638 <https://github.com/fmtlib/fmt/issues/2638>, #2653 <https://github.com/fmtlib/fmt/issues/2653>, #2654 <https://github.com/fmtlib/fmt/issues/2654>, #2661 <https://github.com/fmtlib/fmt/issues/2661>, #2664 <https://github.com/fmtlib/fmt/pull/2664>, #2684 <https://github.com/fmtlib/fmt/pull/2684>). Thanks @DanielaE (Daniela Engert) <https://github.com/DanielaE>, @mwinterb <https://github.com/mwinterb>, @cdacamar (Cameron DaCamara) <https://github.com/cdacamar>, @TrebledJ (Johnathan) <https://github.com/TrebledJ>, @bodomartin (brm) <https://github.com/bodomartin>, @cquammen (Cory Quammen) <https://github.com/cquammen>, @white238 (Chris White) <https://github.com/white238>, @mmarkeloff (Max) <https://github.com/mmarkeloff>, @palacaze (Pierre-Antoine Lacaze) <https://github.com/palacaze>, @jcelerier (Jean-Michaรซl Celerier) <https://github.com/jcelerier>, @mborn-adi (Mathias Born) <https://github.com/mborn-adi>, @BrukerJWD (Jonathan W) <https://github.com/BrukerJWD>, @spyridon97 (Spiros Tsalikis) <https://github.com/spyridon97>, @phprus (Vladislav Shchapov) <https://github.com/phprus>, @oliverlee (Oliver Lee) <https://github.com/oliverlee>, @joshessman-llnl (Josh Essman) <https://github.com/joshessman-llnl>, @akohlmey (Axel Kohlmeyer) <https://github.com/akohlmey>, @timkalu <https://github.com/timkalu>, @olupton (Olli Lupton) <https://github.com/olupton>, @Acretock <https://github.com/Acretock>, @alexezeder (Alexey Ochapov) <https://github.com/alexezeder>, @andrewcorrigan (Andrew Corrigan) <https://github.com/andrewcorrigan>, @lucpelletier <https://github.com/lucpelletier>, @HazardyKnusperkeks (Bjรถrn Schรคpers) <https://github.com/HazardyKnusperkeks>.