C++ Format v5.2.0 Release Notes

Release Date: 2018-09-13 // over 5 years ago
    • ⚡️ Optimized format string parsing and argument processing which resulted in up to 5x speed up on long format strings and significant performance boost on various benchmarks. For example, version 5.2 is 2.22x faster than 5.1 on decimal integer formatting with format_to (macOS, clang-902.0.39.2):

    ================== ======= ======= Method Time, s Speedup ================== ======= ======= fmt::format 5.1 0.58 fmt::format 5.2 0.35 1.66x fmt::format_to 5.1 0.51 fmt::format_to 5.2 0.23 2.22x sprintf 0.71 std::to_string 1.01 std::stringstream 1.73 ================== ======= =======

    • 🔄 Changed the fmt macro from opt-out to opt-in to prevent name collisions. To enable it define the FMT_STRING_ALIAS macro to 1 before including fmt/format.h:

    .. code:: c++

     #define FMT_STRING_ALIAS 1
     #include <fmt/format.h>
     std::string answer = format(fmt("{}"), 42);
    
    • ➕ Added compile-time format string checks to format_to overload that takes fmt::memory_buffer (#783 <https://github.com/fmtlib/fmt/issues/783>_):

    .. code:: c++

     fmt::memory_buffer buf;
     // Compile-time error: invalid type specifier.
     fmt::format_to(buf, fmt("{:d}"), "foo");
    
    • 🚚 Moved experimental color support to fmt/color.h and enabled the new API by default. The old API can be enabled by defining the FMT_DEPRECATED_COLORS macro.

    • ➕ Added formatting support for types explicitly convertible to fmt::string_view:

    .. code:: c++

     struct foo {
       explicit operator fmt::string_view() const { return "foo"; }
     };
     auto s = format("{}", foo());
    

    In particular, this makes formatting function work with folly::StringPiece.

    • 👍 Implemented preliminary support for char*_t by replacing the format function overloads with a single function template parameterized on the string type.

    • ➕ Added support for dynamic argument lists (#814 <https://github.com/fmtlib/fmt/issues/814>, #819 <https://github.com/fmtlib/fmt/pull/819>). Thanks @MikePopoloski (Michael Popoloski) <https://github.com/MikePopoloski>_.

    • ⬇️ Reduced executable size overhead for embedded targets using newlib nano by making locale dependency optional (#839 <https://github.com/fmtlib/fmt/pull/839>). Thanks @teajay-fr (Thomas Benard) <https://github.com/teajay-fr>.

    • Keep noexcept specifier when exceptions are disabled (#801 <https://github.com/fmtlib/fmt/issues/801>, #810 <https://github.com/fmtlib/fmt/pull/810>). Thanks @qis (Alexej Harm) <https://github.com/qis>_.

    • 🛠 Fixed formatting of user-defined types providing operator<< with format_to_n (#806 <https://github.com/fmtlib/fmt/pull/806>). Thanks @mkurdej (Marek Kurdej) <https://github.com/mkurdej>.

    • 🛠 Fixed dynamic linkage of new symbols (#808 <https://github.com/fmtlib/fmt/issues/808>_).

    • 🛠 Fixed global initialization issue (#807 <https://github.com/fmtlib/fmt/issues/807>_):

    .. code:: c++

     // This works on compilers with constexpr support.
     static const std::string answer = fmt::format("{}", 42);
    
    • 🛠 Fixed various compiler warnings and errors (#804 <https://github.com/fmtlib/fmt/pull/804>, #809 <https://github.com/fmtlib/fmt/issues/809>, #811 <https://github.com/fmtlib/fmt/pull/811>, #822 <https://github.com/fmtlib/fmt/issues/822>, #827 <https://github.com/fmtlib/fmt/pull/827>, #830 <https://github.com/fmtlib/fmt/issues/830>, #838 <https://github.com/fmtlib/fmt/pull/838>, #843 <https://github.com/fmtlib/fmt/issues/843>, #844 <https://github.com/fmtlib/fmt/pull/844>, #851 <https://github.com/fmtlib/fmt/issues/851>, #852 <https://github.com/fmtlib/fmt/pull/852>, #854 <https://github.com/fmtlib/fmt/pull/854>). Thanks @henryiii (Henry Schreiner) <https://github.com/henryiii>, @medithe <https://github.com/medithe>, and @eliasdaler (Elias Daler) <https://github.com/eliasdaler>_.