C++ Format v9.0.0 Release Notes

Release Date: 2022-07-04 // about 1 month ago
    • Switched to the internal floating point formatter for all decimal presentation formats. In particular this results in consistent rounding on all platforms and removing the s[n]printf fallback for decimal FP formatting.

    • Compile-time floating point formatting no longer requires the header-only mode. For example (godbolt <https://godbolt.org/z/G37PTeG3b>__):

    .. code:: c++

     #include <array>
     #include <fmt/compile.h>
    
     consteval auto compile_time_dtoa(double value) -> std::array<char, 10> {
       auto result = std::array<char, 10>();
       fmt::format_to(result.data(), FMT_COMPILE("{}"), value);
       return result;
     }
    
     constexpr auto answer = compile_time_dtoa(0.42);
    

    works with the default settings.

    • 👌 Improved the implementation of Dragonbox <https://github.com/jk-jeon/dragonbox>, the algorithm used for the default floating-point formatting (#2713 <https://github.com/fmtlib/fmt/pull/2713>, #2750 <https://github.com/fmtlib/fmt/pull/2750>). Thanks @jk-jeon (Junekey Jeon) <https://github.com/jk-jeon>.

    • Made fmt::to_string work with __float128. This uses the internal FP formatter and works even on system without __float128 support in [s]printf.

    • Disabled automatic std::ostream insertion operator (operator<<) discovery when fmt/ostream.h is included to prevent ODR violations. You can get the old behavior by defining FMT_DEPRECATED_OSTREAM but this will be removed in the next major release. Use fmt::streamed or fmt::ostream_formatter to enable formatting via std::ostream instead.

    • ➕ Added fmt::ostream_formatter that can be used to write formatter specializations that perform formatting via std::ostream. For example (godbolt <https://godbolt.org/z/5sEc5qMsf>__):

    .. code:: c++

     #include <fmt/ostream.h>
    
     struct date {
       int year, month, day;
    
       friend std::ostream& operator<<(std::ostream& os, const date& d) {
         return os << d.year << '-' << d.month << '-' << d.day;
       }
     };
    
     template <> struct fmt::formatter<date> : ostream_formatter {};
    
     std::string s = fmt::format("The date is {}", date{2012, 12, 9});
     // s == "The date is 2012-12-9"
    
    • ➕ Added the fmt::streamed function that takes an object and formats it via std::ostream. For example (godbolt <https://godbolt.org/z/5G3346G1f>__):

    .. code:: c++

     #include <thread>
     #include <fmt/ostream.h>
    
     int main() {
       fmt::print("Current thread id: {}\n",
                  fmt::streamed(std::this_thread::get_id()));
     }
    

    Note that fmt/std.h provides a formatter specialization for std::thread::id so you don't need to format it via std::ostream.

    • 🗄 Deprecated implicit conversions of unscoped enums to integers for consistency with scoped enums.

    • ➕ Added an argument-dependent lookup based format_as extension API to simplify formatting of enums.

    • ➕ Added experimental std::variant formatting support (#2941 <https://github.com/fmtlib/fmt/pull/2941>). For example (godbolt <https://godbolt.org/z/KG9z6cq68>_):

    .. code:: c++

     #include <variant>
     #include <fmt/std.h>
    
     int main() {
       auto v = std::variant<int, std::string>(42);
       fmt::print("{}\n", v);
     }
    

    prints::

     variant(42)
    

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

    • ➕ Added experimental std::filesystem::path formatting support (#2865 <https://github.com/fmtlib/fmt/issues/2865>, #2902 <https://github.com/fmtlib/fmt/pull/2902>, #2917 <https://github.com/fmtlib/fmt/issues/2917>, #2918 <https://github.com/fmtlib/fmt/pull/2918>). For example (godbolt <https://godbolt.org/z/o44dMexEb>__):

    .. code:: c++

     #include <filesystem>
     #include <fmt/std.h>
    
     int main() {
       fmt::print("There is no place like {}.", std::filesystem::path("/home"));
     }
    

    prints::

     There is no place like "/home".
    

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

    • ➕ Added a std::thread::id formatter to fmt/std.h. For example (godbolt <https://godbolt.org/z/j1azbYf3E>__):

    .. code:: c++

     #include <thread>
     #include <fmt/std.h>
    
     int main() {
       fmt::print("Current thread id: {}\n", std::this_thread::get_id());
     }
    
    • ➕ Added fmt::styled that applies a text style to an individual argument (#2793 <https://github.com/fmtlib/fmt/pull/2793>). For example (godbolt <https://godbolt.org/z/vWGW7v5M6>_):

    .. code:: c++

     #include <fmt/chrono.h>
     #include <fmt/color.h>
    
     int main() {
       auto now = std::chrono::system_clock::now();
       fmt::print(
         "[{}] {}: {}\n",
         fmt::styled(now, fmt::emphasis::bold),
         fmt::styled("error", fg(fmt::color::red)),
         "something went wrong");
     }
    

    prints

    .. image:: https://user-images.githubusercontent.com/576385/ 175071215-12809244-dab0-4005-96d8-7cd911c964d5.png

    Thanks @rbrugo (Riccardo Brugo) <https://github.com/rbrugo>_.

    • 💅 Made fmt::print overload for text styles correctly handle UTF-8 (#2681 <https://github.com/fmtlib/fmt/issues/2681>, #2701 <https://github.com/fmtlib/fmt/pull/2701>). Thanks @AlexGuteniev (Alex Guteniev) <https://github.com/AlexGuteniev>_.

    • 🛠 Fixed Unicode handling when writing to an ostream.

    • ➕ Added support for nested specifiers to range formatting (#2673 <https://github.com/fmtlib/fmt/pull/2673>). For example (godbolt <https://godbolt.org/z/xd3Gj38cf>_):

    .. code:: c++

     #include <vector>
     #include <fmt/ranges.h>
    
     int main() {
       fmt::print("{::#x}\n", std::vector{10, 20, 30});
     }
    

    prints [0xa, 0x14, 0x1e].

    Thanks @BRevzin (Barry Revzin) <https://github.com/BRevzin>_.

    • Implemented escaping of wide strings in ranges (#2904 <https://github.com/fmtlib/fmt/pull/2904>). Thanks @phprus (Vladislav Shchapov) <https://github.com/phprus>.

    • ➕ Added support for ranges with begin / end found via the argument-dependent lookup (#2807 <https://github.com/fmtlib/fmt/pull/2807>). Thanks @rbrugo (Riccardo Brugo) <https://github.com/rbrugo>.

    • 🛠 Fixed formatting of certain kinds of ranges of ranges (#2787 <https://github.com/fmtlib/fmt/pull/2787>). Thanks @BRevzin (Barry Revzin) <https://github.com/BRevzin>.

    • 🛠 Fixed handling of maps with element types other than std::pair (#2944 <https://github.com/fmtlib/fmt/pull/2944>). Thanks @BrukerJWD (Jonathan W) <https://github.com/BrukerJWD>.

    • Made tuple formatter enabled only if elements are formattable (#2939 <https://github.com/fmtlib/fmt/issues/2939>, #2940 <https://github.com/fmtlib/fmt/pull/2940>). Thanks @jehelset <https://github.com/jehelset>_.

    • Made fmt::join compatible with format string compilation (#2719 <https://github.com/fmtlib/fmt/issues/2719>, #2720 <https://github.com/fmtlib/fmt/pull/2720>). Thanks @phprus (Vladislav Shchapov) <https://github.com/phprus>_.

    • Made compile-time checks work with named arguments of custom types and std::ostream print overloads (#2816 <https://github.com/fmtlib/fmt/issues/2816>, #2817 <https://github.com/fmtlib/fmt/issues/2817>, #2819 <https://github.com/fmtlib/fmt/pull/2819>). Thanks @timsong-cpp <https://github.com/timsong-cpp>.

    • Removed make_args_checked because it is no longer needed for compile-time checks (#2760 <https://github.com/fmtlib/fmt/pull/2760>). Thanks @phprus (Vladislav Shchapov) <https://github.com/phprus>.

    • Removed the following deprecated APIs: _format, arg_join, the format_to overload that takes a memory buffer, [v]fprintf that takes an ostream.

    • ✂ Removed the deprecated implicit conversion of [const] signed char* and [const] unsigned char* to C strings.

    • ✂ Removed the deprecated fmt/locale.h.

    • 🗄 Replaced the deprecated fileno() with descriptor() in buffered_file.

    • Moved to_string_view to the detail namespace since it's an implementation detail.

    • Made access mode of a created file consistent with fopen by setting S_IWGRP and S_IWOTH (#2733 <https://github.com/fmtlib/fmt/pull/2733>). Thanks @arogge (Andreas Rogge) <https://github.com/arogge>.

    • ✂ Removed a redundant buffer resize when formatting to std::ostream (#2842 <https://github.com/fmtlib/fmt/issues/2842>, #2843 <https://github.com/fmtlib/fmt/pull/2843>). Thanks @jcelerier (Jean-Michaël Celerier) <https://github.com/jcelerier>_.

    • Made precision computation for strings consistent with width (#2888 <https://github.com/fmtlib/fmt/issues/2888>_).

    • 🛠 Fixed handling of locale separators in floating point formatting (#2830 <https://github.com/fmtlib/fmt/issues/2830>_).

    • Made sign specifiers work with __int128_t (#2773 <https://github.com/fmtlib/fmt/issues/2773>_).

    • 👌 Improved support for systems such as CHERI with extra data stored in pointers (#2932 <https://github.com/fmtlib/fmt/pull/2932>). Thanks @davidchisnall (David Chisnall) <https://github.com/davidchisnall>.

    • 👌 Improved documentation (#2706 <https://github.com/fmtlib/fmt/pull/2706>, #2712 <https://github.com/fmtlib/fmt/pull/2712>, #2789 <https://github.com/fmtlib/fmt/pull/2789>, #2803 <https://github.com/fmtlib/fmt/pull/2803>, #2805 <https://github.com/fmtlib/fmt/pull/2805>, #2815 <https://github.com/fmtlib/fmt/pull/2815>, #2924 <https://github.com/fmtlib/fmt/pull/2924>). Thanks @BRevzin (Barry Revzin) <https://github.com/BRevzin>, @Pokechu22 <https://github.com/Pokechu22>, @setoye (Alta) <https://github.com/setoye>, @rtobar <https://github.com/rtobar>, @rbrugo (Riccardo Brugo) <https://github.com/rbrugo>, @anoonD (cre) <https://github.com/anoonD>, @leha-bot (Alex) <https://github.com/leha-bot>.

    • 👌 Improved build configuration (#2766 <https://github.com/fmtlib/fmt/pull/2766>, #2772 <https://github.com/fmtlib/fmt/pull/2772>, #2836 <https://github.com/fmtlib/fmt/pull/2836>, #2852 <https://github.com/fmtlib/fmt/pull/2852>, #2907 <https://github.com/fmtlib/fmt/pull/2907>, #2913 <https://github.com/fmtlib/fmt/pull/2913>, #2914 <https://github.com/fmtlib/fmt/pull/2914>). Thanks @kambala-decapitator (Andrey Filipenkov) <https://github.com/kambala-decapitator>, @mattiasljungstrom (Mattias Ljungström) <https://github.com/mattiasljungstrom>, @kieselnb (Nick Kiesel) <https://github.com/kieselnb>, @nathannaveen <https://github.com/nathannaveen>, @Vertexwahn <https://github.com/Vertexwahn>.

    • 🛠 Fixed various warnings and compilation issues (#2408 <https://github.com/fmtlib/fmt/issues/2408>, #2507 <https://github.com/fmtlib/fmt/issues/2507>, #2697 <https://github.com/fmtlib/fmt/issues/2697>, #2715 <https://github.com/fmtlib/fmt/issues/2715>, #2717 <https://github.com/fmtlib/fmt/issues/2717>, #2722 <https://github.com/fmtlib/fmt/pull/2722>, #2724 <https://github.com/fmtlib/fmt/pull/2724>, #2725 <https://github.com/fmtlib/fmt/pull/2725>, #2726 <https://github.com/fmtlib/fmt/issues/2726>, #2728 <https://github.com/fmtlib/fmt/pull/2728>, #2732 <https://github.com/fmtlib/fmt/pull/2732>, #2738 <https://github.com/fmtlib/fmt/issues/2738>, #2742 <https://github.com/fmtlib/fmt/pull/2742>, #2744 <https://github.com/fmtlib/fmt/issues/2744>, #2745 <https://github.com/fmtlib/fmt/issues/2745>, #2746 <https://github.com/fmtlib/fmt/issues/2746>, #2754 <https://github.com/fmtlib/fmt/issues/2754>, #2755 <https://github.com/fmtlib/fmt/pull/2755>, #2757 <https://github.com/fmtlib/fmt/issues/2757>, #2758 <https://github.com/fmtlib/fmt/pull/2758>, #2761 <https://github.com/fmtlib/fmt/issues/2761>, #2762 <https://github.com/fmtlib/fmt/pull/2762>, #2763 <https://github.com/fmtlib/fmt/issues/2763>, #2765 <https://github.com/fmtlib/fmt/pull/2765>, #2769 <https://github.com/fmtlib/fmt/issues/2769>, #2770 <https://github.com/fmtlib/fmt/pull/2770>, #2771 <https://github.com/fmtlib/fmt/issues/2771>, #2777 <https://github.com/fmtlib/fmt/issues/2777>, #2779 <https://github.com/fmtlib/fmt/pull/2779>, #2782 <https://github.com/fmtlib/fmt/pull/2782>, #2783 <https://github.com/fmtlib/fmt/pull/2783>, #2794 <https://github.com/fmtlib/fmt/issues/2794>, #2796 <https://github.com/fmtlib/fmt/issues/2796>, #2797 <https://github.com/fmtlib/fmt/pull/2797>, #2801 <https://github.com/fmtlib/fmt/pull/2801>, #2802 <https://github.com/fmtlib/fmt/pull/2802>, #2808 <https://github.com/fmtlib/fmt/issues/2808>, #2818 <https://github.com/fmtlib/fmt/issues/2818>, #2819 <https://github.com/fmtlib/fmt/pull/2819>, #2829 <https://github.com/fmtlib/fmt/issues/2829>, #2835 <https://github.com/fmtlib/fmt/issues/2835>, #2848 <https://github.com/fmtlib/fmt/issues/2848>, #2860 <https://github.com/fmtlib/fmt/issues/2860>, #2861 <https://github.com/fmtlib/fmt/pull/2861>, #2882 <https://github.com/fmtlib/fmt/pull/2882>, #2886 <https://github.com/fmtlib/fmt/issues/2886>, #2891 <https://github.com/fmtlib/fmt/issues/2891>, #2892 <https://github.com/fmtlib/fmt/pull/2892>, #2895 <https://github.com/fmtlib/fmt/issues/2895>, #2896 <https://github.com/fmtlib/fmt/issues/2896>, #2903 <https://github.com/fmtlib/fmt/pull/2903>, #2906 <https://github.com/fmtlib/fmt/issues/2906>, #2908 <https://github.com/fmtlib/fmt/issues/2908>, #2909 <https://github.com/fmtlib/fmt/pull/2909>, #2920 <https://github.com/fmtlib/fmt/issues/2920>, #2922 <https://github.com/fmtlib/fmt/pull/2922>, #2927 <https://github.com/fmtlib/fmt/pull/2927>, #2929 <https://github.com/fmtlib/fmt/pull/2929>, #2936 <https://github.com/fmtlib/fmt/issues/2936>, #2937 <https://github.com/fmtlib/fmt/pull/2937>, #2938 <https://github.com/fmtlib/fmt/pull/2938>, #2951 <https://github.com/fmtlib/fmt/pull/2951>, #2954 <https://github.com/fmtlib/fmt/issues/2954>, #2957 <https://github.com/fmtlib/fmt/pull/2957>, #2958 <https://github.com/fmtlib/fmt/issues/2958>, #2960 <https://github.com/fmtlib/fmt/pull/2960>). Thanks @matrackif <https://github.com/matrackif>_ @Tobi823 (Tobias Hellmann) <https://github.com/Tobi823>, @ivan-volnov (Ivan Volnov) <https://github.com/ivan-volnov>, @VasiliPupkin256 <https://github.com/VasiliPupkin256>, @federico-busato (Federico) <https://github.com/federico-busato>, @barcharcraz (Charlie Barto) <https://github.com/barcharcraz>, @jk-jeon (Junekey Jeon) <https://github.com/jk-jeon>, @HazardyKnusperkeks (Björn Schäpers) <https://github.com/HazardyKnusperkeks>, @dalboris (Boris Dalstein) <https://github.com/dalboris>, @seanm (Sean McBride) <https://github.com/seanm>, @gsjaardema (Greg Sjaardema) <https://github.com/gsjaardema>, @timsong-cpp <https://github.com/timsong-cpp>, @seanm (Sean McBride) <https://github.com/seanm>, @frithrah <https://github.com/frithrah>, @chronoxor (Ivan Shynkarenka) <https://github.com/chronoxor>, @Agga <https://github.com/Agga>, @madmaxoft (Mattes D) <https://github.com/madmaxoft>, @JurajX (Juraj) <https://github.com/JurajX>, @phprus (Vladislav Shchapov) <https://github.com/phprus>, @Dani-Hub (Daniel Krügler) <https://github.com/Dani-Hub>_.


Previous changes from v8.1.1

    • ⏪ Restored ABI compatibility with version 8.0.x (#2695 <https://github.com/fmtlib/fmt/issues/2695>, #2696 <https://github.com/fmtlib/fmt/pull/2696>). Thanks @saraedum (Julian Rüth) <https://github.com/saraedum>_.

    • 🛠 Fixed chrono formatting on big endian systems (#2698 <https://github.com/fmtlib/fmt/issues/2698>, #2699 <https://github.com/fmtlib/fmt/pull/2699>). Thanks @phprus (Vladislav Shchapov) <https://github.com/phprus>_ and @xvitaly (Vitaly Zaitsev) <https://github.com/xvitaly>_.

    • 🛠 Fixed a linkage error with mingw (#2691 <https://github.com/fmtlib/fmt/issues/2691>, #2692 <https://github.com/fmtlib/fmt/pull/2692>). Thanks @rbberger (Richard Berger) <https://github.com/rbberger>_.