C++ Format v9.1.0 Release Notes

Release Date: 2022-08-27 // over 1 year ago
    • fmt::formatted_size now works at compile time (#3026 <https://github.com/fmtlib/fmt/pull/3026>). For example (godbolt <https://godbolt.org/z/1MW5rMdf8>_):

    .. code:: c++

     #include <fmt/compile.h>
    
     int main() {
       using namespace fmt::literals;
       constexpr size_t n = fmt::formatted_size("{}"_cf, 42);
       fmt::print("{}\n", n); // prints 2
     }
    

    Thanks @marksantaniello (Mark Santaniello) <https://github.com/marksantaniello>_.

    • ๐Ÿ›  Fixed handling of invalid UTF-8 (#3038 <https://github.com/fmtlib/fmt/pull/3038>, #3044 <https://github.com/fmtlib/fmt/pull/3044>, #3056 <https://github.com/fmtlib/fmt/pull/3056>). Thanks @phprus (Vladislav Shchapov) <https://github.com/phprus> and @skeeto (Christopher Wellons) <https://github.com/skeeto>_.

    • ๐Ÿ‘Œ Improved Unicode support in ostream overloads of print (#2994 <https://github.com/fmtlib/fmt/pull/2994>, #3001 <https://github.com/fmtlib/fmt/pull/3001>, #3025 <https://github.com/fmtlib/fmt/pull/3025>). Thanks @dimztimz (Dimitrij Mijoski) <https://github.com/dimztimz>.

    • ๐Ÿ›  Fixed handling of the sign specifier in localized formatting on systems with 32-bit wchar_t (#3041 <https://github.com/fmtlib/fmt/issues/3041>_).

    • โž• Added support for wide streams to fmt::streamed (#2994 <https://github.com/fmtlib/fmt/pull/2994>). Thanks @phprus (Vladislav Shchapov) <https://github.com/phprus>.

    • โž• Added the n specifier that disables the output of delimiters when formatting ranges (#2981 <https://github.com/fmtlib/fmt/pull/2981>, #2983 <https://github.com/fmtlib/fmt/pull/2983>). For example (godbolt <https://godbolt.org/z/roKqGdj8c>__):

    .. code:: c++

     #include <fmt/ranges.h>
     #include <vector>
    
     int main() {
       auto v = std::vector{1, 2, 3};
       fmt::print("{:n}\n", v); // prints 1, 2, 3
     }
    

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

    • Worked around problematic std::string_view constructors introduced in C++23 (#3030 <https://github.com/fmtlib/fmt/issues/3030>, #3050 <https://github.com/fmtlib/fmt/issues/3050>). Thanks @strega-nil-ms (nicole mazzuca) <https://github.com/strega-nil-ms>_.

    • ๐Ÿ‘Œ Improve handling (exclusion) of recursive ranges (#2968 <https://github.com/fmtlib/fmt/issues/2968>, #2974 <https://github.com/fmtlib/fmt/pull/2974>). Thanks @Dani-Hub (Daniel Krรผgler) <https://github.com/Dani-Hub>_.

    • ๐Ÿ‘Œ Improved error reporting in format string compilation (#3055 <https://github.com/fmtlib/fmt/issues/3055>_).

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

    • ๐Ÿ›  Fixed issues with floating-point formatting on exotic platforms.

    • ๐Ÿ‘Œ Improved the implementation of chrono formatting (#3010 <https://github.com/fmtlib/fmt/pull/3010>). Thanks @phprus (Vladislav Shchapov) <https://github.com/phprus>.

    • ๐Ÿ‘Œ Improved documentation (#2966 <https://github.com/fmtlib/fmt/pull/2966>, #3009 <https://github.com/fmtlib/fmt/pull/3009>, #3020 <https://github.com/fmtlib/fmt/issues/3020>, #3037 <https://github.com/fmtlib/fmt/pull/3037>). Thanks @mwinterb <https://github.com/mwinterb>, @jcelerier (Jean-Michaรซl Celerier) <https://github.com/jcelerier> and @remiburtin (Rรฉmi Burtin) <https://github.com/remiburtin>_.

    • ๐Ÿ‘Œ Improved build configuration (#2991 <https://github.com/fmtlib/fmt/pull/2991>, #2995 <https://github.com/fmtlib/fmt/pull/2995>, #3004 <https://github.com/fmtlib/fmt/issues/3004>, #3007 <https://github.com/fmtlib/fmt/pull/3007>, #3040 <https://github.com/fmtlib/fmt/pull/3040>). Thanks @dimztimz (Dimitrij Mijoski) <https://github.com/dimztimz> and @hwhsu1231 (Haowei Hsu) <https://github.com/hwhsu1231>_.

    • ๐Ÿ›  Fixed various warnings and compilation issues (#2969 <https://github.com/fmtlib/fmt/issues/2969>, #2971 <https://github.com/fmtlib/fmt/pull/2971>, #2975 <https://github.com/fmtlib/fmt/issues/2975>, #2982 <https://github.com/fmtlib/fmt/pull/2982>, #2985 <https://github.com/fmtlib/fmt/pull/2985>, #2988 <https://github.com/fmtlib/fmt/issues/2988>, #3000 <https://github.com/fmtlib/fmt/issues/3000>, #3006 <https://github.com/fmtlib/fmt/issues/3006>, #3014 <https://github.com/fmtlib/fmt/issues/3014>, #3015 <https://github.com/fmtlib/fmt/issues/3015>, #3021 <https://github.com/fmtlib/fmt/pull/3021>, #3023 <https://github.com/fmtlib/fmt/issues/3023>, #3024 <https://github.com/fmtlib/fmt/pull/3024>, #3029 <https://github.com/fmtlib/fmt/pull/3029>, #3043 <https://github.com/fmtlib/fmt/pull/3043>, #3052 <https://github.com/fmtlib/fmt/issues/3052>, #3053 <https://github.com/fmtlib/fmt/pull/3053>, #3054 <https://github.com/fmtlib/fmt/pull/3054>). Thanks @h-friederich (Hannes Friederich) <https://github.com/h-friederich>, @dimztimz (Dimitrij Mijoski) <https://github.com/dimztimz>, @olupton (Olli Lupton) <https://github.com/olupton>, @bernhardmgruber (Bernhard Manfred Gruber) <https://github.com/bernhardmgruber>, @phprus (Vladislav Shchapov) <https://github.com/phprus>_.


Previous changes from v9.0.0

    • 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>_.