Skip to content

11.0.0

Compare
Choose a tag to compare
@vitaut vitaut released this 01 Jul 13:11
  • Added fmt/base.h which provides a subset of the API with minimal include dependencies and enough functionality to replace all uses of the printf family of functions. This brings the compile time of code using {fmt} much closer to the equivalent printf code as shown on the following benchmark that compiles 100 source files:

    Method Compile Time (s)
    printf 1.6
    IOStreams 25.9
    fmt 10.x 19.0
    fmt 11.0 4.8
    tinyformat 29.1
    Boost Format 55.0

    This gives almost 4x improvement in build speed compared to version 10. Note that the benchmark is purely formatting code and includes. In real projects the difference from printf will be smaller partly because common standard headers will be included in almost any translation unit (TU) anyway. In particular, in every case except printf above ~1s is spent in total on including <type_traits> in all TUs.

  • Optimized includes in other headers such as fmt/format.h which is now roughly equivalent to the old fmt/core.h in terms of build speed.

  • Migrated the documentation at https://fmt.dev/ from Sphinx to MkDocs.

  • Improved C++20 module support (#3990, #3991, #3993, #3994, #3997, #3998, #4004, #4005, #4006, #4013, #4027, #4029). In particular, native CMake support for modules is now used if available. Thanks @yujincheng08 and @matt77hias.

  • Added an option to replace standard includes with import std enabled via the FMT_IMPORT_STD macro (#3921, #3928). Thanks @matt77hias.

  • Exported fmt::range_format, fmt::range_format_kind and fmt::compiled_string from the fmt module (#3970, #3999). Thanks @matt77hias and @yujincheng08.

  • Improved integration with stdio in fmt::print, enabling direct writes into a C stream buffer in common cases. This may give significant performance improvements ranging from tens of percent to 2x and eliminates dynamic memory allocations on the buffer level. It is currently enabled for built-in and string types with wider availability coming up in future releases.

    For example, it gives ~24% improvement on a simple benchmark compiled with Apple clang version 15.0.0 (clang-1500.1.0.2.5) and run on macOS 14.2.1:

    -------------------------------------------------------
    Benchmark             Time             CPU   Iterations
    -------------------------------------------------------
    printf             81.8 ns         81.5 ns      8496899
    fmt::print (10.x)  63.8 ns         61.9 ns     11524151
    fmt::print (11.0)  51.3 ns         51.0 ns     13846580
    
  • Improved safety of fmt::format_to when writing to an array (#3805). For example (godbolt):

    auto volkswagen = char[4];
    auto result = fmt::format_to(volkswagen, "elephant");

    no longer results in a buffer overflow. Instead the output will be truncated and you can get the end iterator and whether truncation occurred from the result object. Thanks @ThePhD.

  • Enabled Unicode support by default in MSVC, bringing it on par with other compilers and making it unnecessary for users to enable it explicitly. Most of {fmt} is encoding-agnostic but this prevents mojibake in places where encoding matters such as path formatting and terminal output. You can control the Unicode support via the CMake FMT_UNICODE option. Note that some {fmt} packages such as the one in vcpkg have already been compiled with Unicode enabled.

  • Added a formatter for std::expected (#3834). Thanks @dominicpoeschko.

  • Added a formatter for std::complex (#1467, #3886, #3892, #3900). Thanks @phprus.

  • Added a formatter for std::type_info (#3978). Thanks @matt77hias.

  • Specialized formatter for std::basic_string types with custom traits and allocators (#3938, #3943). Thanks @dieram3.

  • Added formatters for std::chrono::day, std::chrono::month, std::chrono::year and std::chrono::year_month_day (#3758, #3772, #3906, #3913). For example:

    #include <fmt/chrono.h>
    #include <fmt/color.h>
    
    int main() {
      fmt::print(fg(fmt::color::green), "{}\n", std::chrono::day(7));
    }

    prints a green day:

    image

    Thanks @zivshek.

  • Fixed handling of precision in %S (#3794, #3814). Thanks @js324.

  • Added support for the - specifier (glibc strftime extension) to day of the month (%d) and week of the year (%W, %U, %V) specifiers (#3976). Thanks @ZaheenJ.

  • Fixed the scope of the - extension in chrono formatting so that it doesn't apply to subsequent specifiers (#3811, #3812). Thanks @phprus.

  • Improved handling of time_point::min() (#3282).

  • Added support for character range formatting (#3857, #3863). Thanks @js324.

  • Added string and debug_string range formatters (#3973, #4024). Thanks @matt77hias.

  • Enabled ADL for begin and end in fmt::join (#3813, #3824). Thanks @bbolli.

  • Made contiguous iterator optimizations apply to std::basic_string iterators (#3798). Thanks @phprus.

  • Added support for ranges with mutable begin and end (#3752, #3800, #3955). Thanks @tcbrindle and @Arghnews.

  • Added support for move-only iterators to fmt::join (#3802, #3946). Thanks @Arghnews.

  • Moved range and iterator overloads of fmt::join to fmt/ranges.h, next to other overloads.

  • Fixed handling of types with begin returning void such as Eigen matrices (#3839, #3964). Thanks @Arghnews.

  • Added an fmt::formattable concept (#3974). Thanks @matt77hias.

  • Added support for __float128 (#3494).

  • Fixed rounding issues when formatting long double with fixed precision (#3539).

  • Made fmt::isnan not trigger floating-point exception for NaN values (#3948, #3951). Thanks @alexdewar.

  • Removed dependency on <memory> for std::allocator_traits when possible (#3804). Thanks @phprus.

  • Enabled compile-time checks in formatting functions that take text colors and styles.

  • Deprecated wide stream overloads of fmt::print that take text styles.

  • Made format string compilation work with clang 12 and later despite only partial non-type template parameter support (#4000, #4001). Thanks @yujincheng08.

  • Made fmt::iterator_buffer's move constructor noexcept (#3808). Thanks @waywardmonkeys.

  • Started enforcing that formatter::format is const for compatibility with std::format (#3447).

  • Added fmt::basic_format_arg::visit and deprecated fmt::visit_format_arg.

  • Made fmt::basic_string_view not constructible from nullptr for consistency with std::string_view in C++23 (#3846). Thanks @dalle.

  • Fixed fmt::group_digits for negative integers (#3891, #3901). Thanks @phprus.

  • Fixed handling of negative ids in fmt::basic_format_args::get (#3945). Thanks @marlenecota.

  • Improved named argument validation (#3817).

  • Disabled copy construction/assignment for fmt::format_arg_store and fixed moved construction (#3833). Thanks @ivafanas.

  • Worked around a locale issue in RHEL/devtoolset (#3858, #3859). Thanks @g199209.

  • Added RTTI detection for MSVC (#3821, #3963). Thanks @edo9300.

  • Migrated the documentation from Sphinx to MkDocs.

  • Improved documentation and README (#3775, #3784, #3788, #3789, #3793, #3818, #3820, #3822, #3843, #3890, #3894, #3895, #3905, #3942, #4008). Thanks @zencatalyst, WolleTD, @tupaschoal, @Dobiasd, @frank-weinberg, @bbolli, @phprus, @waywardmonkeys, @js324 and @tchaikov.

  • Improved CI and tests (#3878, #3883, #3897, #3979, #3980, #3988, #4010, #4012, #4038). Thanks @vgorrX, @waywardmonkeys, @tchaikov and @phprus.

  • Fixed buffer overflow when using format string compilation with debug format and std::back_insert_iterator (#3795, #3797). Thanks @phprus.

  • Improved Bazel support (#3792, #3801, #3962, #3965). Thanks @Vertexwahn.

  • Improved/fixed the CMake config (#3777, #3783, #3847, #3907). Thanks @phprus and @xTachyon.

  • Fixed various warnings and compilation issues (#3685, #3769, #3796, #3803, #3806, #3807, #3809, #3810, #3830, #3832, #3835, #3844, #3854, #3856, #3865, #3866, #3880, #3881, #3884, #3898, #3899, #3909, #3917, #3923, #3924, #3925, #3930, #3931, #3933, #3935, #3937, #3967, #3968, #3972, #3983, #3992, #3995, #4009, #4023). Thanks @hmbj, @phprus, @res2k, @Baardi, @matt77hias, @waywardmonkeys, @hmbj, @yakra, @prlw1, @Arghnews, @mtillmann0, @ShifftC, @eepp, @jimmy-park and @ChristianGebhardt.