Skip to content

Releases: fmtlib/fmt

10.0.0

10 May 13:25
Compare
Choose a tag to compare
Read more

9.1.0

27 Aug 16:06
Compare
Choose a tag to compare

Pull Requests

New Contributors

Full Changelog: 9.0.0...9.1.0

9.0.0

05 Jul 13:11
Compare
Choose a tag to compare
Read more

8.1.1

06 Jan 22:52
Compare
Choose a tag to compare

8.1.0

02 Jan 17:17
Compare
Choose a tag to compare

8.0.1

02 Jul 23:23
Compare
Choose a tag to compare

8.0.0

21 Jun 13:16
Compare
Choose a tag to compare
  • Enabled compile-time format string check by default. For example (godbolt):

    #include <fmt/core.h>
    
    int main() {
      fmt::print("{:d}", "I am not a number");
    }

    gives a compile-time error on compilers with C++20 consteval support (gcc 10+, clang 11+) because d is not a valid format specifier for a string.

    To pass a runtime string wrap it in fmt::runtime:

    fmt::print(fmt::runtime("{:d}"), "I am not a number");
  • Added compile-time formatting (#2019, #2044, #2056, #2072, #2075, #2078, #2129, #2326). For example (godbolt):

    #include <fmt/compile.h>
    
    consteval auto compile_time_itoa(int 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_itoa(42);

    Most of the formatting functionality is available at compile time with a notable exception of floating-point numbers and pointers. Thanks @alexezeder (Alexey Ochapov).

  • Optimized handling of format specifiers during format string compilation. For example, hexadecimal formatting ("{:x}") is now 3-7x faster than before when using format_to with format string compilation and a stack-allocated buffer (#1944).

    Before (7.1.3):

    ----------------------------------------------------------------------------
    Benchmark                                  Time             CPU   Iterations
    ----------------------------------------------------------------------------
    FMTCompileOld/0                         15.5 ns         15.5 ns     43302898
    FMTCompileOld/42                        16.6 ns         16.6 ns     43278267
    FMTCompileOld/273123                    18.7 ns         18.6 ns     37035861
    FMTCompileOld/9223372036854775807       19.4 ns         19.4 ns     35243000
    ----------------------------------------------------------------------------
    

    After (8.x):

    ----------------------------------------------------------------------------
    Benchmark                                  Time             CPU   Iterations
    ----------------------------------------------------------------------------
    FMTCompileNew/0                         1.99 ns         1.99 ns    360523686
    FMTCompileNew/42                        2.33 ns         2.33 ns    279865664
    FMTCompileNew/273123                    3.72 ns         3.71 ns    190230315
    FMTCompileNew/9223372036854775807       5.28 ns         5.26 ns    130711631
    ----------------------------------------------------------------------------
    

    It is even faster than std::to_chars from libc++ compiled with clang on macOS:

    ----------------------------------------------------------------------------
    Benchmark                                  Time             CPU   Iterations
    ----------------------------------------------------------------------------
    ToChars/0                               4.42 ns         4.41 ns    160196630
    ToChars/42                              5.00 ns         4.98 ns    140735201
    ToChars/273123                          7.26 ns         7.24 ns     95784130
    ToChars/9223372036854775807             8.77 ns         8.75 ns     75872534
    ----------------------------------------------------------------------------
    

    In other cases, especially involving std::string construction, the speed up is usually lower because handling format specifiers takes a smaller fraction of the total time.

  • Added the _cf user-defined literal to represent a compiled format string. It can be used instead of the FMT_COMPILE macro (#2043, #2242):

    #include <fmt/compile.h>
    
    using namespace fmt::literals;
    auto s = fmt::format(FMT_COMPILE("{}"), 42); // 🙁 not modern
    auto s = fmt::format("{}"_cf, 42);           // 🙂 modern as hell

    It requires compiler support for class types in non-type template parameters (a C++20 feature) which is available in GCC 9.3+. Thanks @alexezeder (Alexey Ochapov).

  • Format string compilation now requires format functions of formatter specializations for user-defined types to be const:

    template <> struct fmt::formatter<my_type>: formatter<string_view> {
      template <typename FormatContext>
      auto format(my_type obj, FormatContext& ctx) const {  // Note const here.
        // ...
      }
    };
  • Added UDL-based named argument support to format string compilation (#2243, #2281). For example:

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

    Here the argument named "answer" is resolved at compile time with no runtime overhead. Thanks @alexezeder (Alexey Ochapov).

  • Added format string compilation support to fmt::print (#2280, #2304). Thanks @alexezeder (Alexey Ochapov).

  • Added initial support for compiling {fmt} as a C++20 module (#2235, #2240, #2260, #2282, #2283, #2288, #2298, #2306, #2307, #2309, #2318, #2324, #2332, #2340). Thanks @DanielaE (Daniela Engert).

  • Made symbols private by default reducing shared library size (#2301). For example there was a ~15% reported reduction on one platform. Thanks @sergiud (Sergiu Deitsch).

  • Optimized includes making the result of preprocessing fmt/format.h ~20% smaller with libstdc++/C++20 and slightly improving build times (#1998).

  • Added support of ranges with non-const begin / end (#1953). Thanks @kitegi (sarah).

  • Added support of std::byte and other formattable types to fmt::join (#1981, #2040, #2050, #2262). For example:

    #include <fmt/format.h>
    #include <cstddef>
    #include <vector>
    
    int main() {
      auto bytes = std::vector{std::byte(4), std::byte(2)};
      fmt::print("{}", fmt::join(bytes, ""));
    }

    prints "42".

    Thanks @kamibo (Camille Bordignon).

  • Implemented the default format for std::chrono::system_clock (#2319, #2345). For example:

    #include <fmt/chrono.h>
    
    int main() {
      fmt::print("{}", std::chrono::system_clock::now());
    }

    prints "2021-06-18 15:22:00" (the output depends on the current date and time). Thanks @sunmy2019.

  • Made more chrono specifiers locale independent by default. Use the 'L' specifier to get localized formatting. For example:

    #include <fmt/chrono.h>
    
    int main() {
      std::locale::global(std::locale("ru_RU.UTF-8"));
      auto monday = std::chrono::weekday(1);
      fmt::print("{}\n", monday);   // prints "Mon"
      fmt::print("{:L}\n", monday); // prints "пн"
    }
  • Improved locale handling in chrono formatting (#2337, #2349, #2350). Thanks @phprus (Vladislav Shchapov).

  • Deprecated fmt/locale.h moving the formatting functions that take a locale to fmt/format.h (char) and fmt/xchar (other overloads). This doesn't introduce a dependency on <locale> so there is virtually no compile time effect.

  • Made parameter order in vformat_to consistent with format_to (#2327).

  • Added support for time points with arbitrary durations (#2208). For example:

    #include <fmt/chrono.h>
    
    int main() {
      using tp = std::chrono::time_point<
        std::chrono::system_clock, std::chrono::seconds>;
      fmt::print("{:%S}", tp(std::chrono::seconds(42)));
    }

    prints "42".

  • Formatting floating-point numbers no longer produces trailing zeros by default for consistency with std::format. For example:

    #include <fmt/core.h>
    
    int main() {
      fmt::print("{0:.3}", 1.1);
    }

    prints "1.1". Use the '#' specifier to keep trailing zeros.

  • Dropped a limit on the number of elements in a range and replaced {} with [] as range delimiters for consistency with Python's str.format.

  • The 'L' specifier for locale-specific numeric formatting can now be combined with presentation specifiers as in std::format. For example:

    #include <fmt/core.h>
    #include <locale>
    
    int main() {
      std::locale::global(std::locale("fr_FR.UTF-8"));
      fmt::print("{0:.2Lf}", 0.42);
    }

    prints "0,42". The deprecated 'n' specifier has been removed.

  • Made the 0 specifier ignored for infinity and NaN (#2305, #2310). Thanks @Liedtke (Matthias Liedtke).

  • Made the hexfloat formatting use the right alignment by default (#2308, #2317). Thanks @Liedtke (Matthias Liedtke).

  • Removed the deprecated numeric alignment ('='). Use the '0' specifier instead.

  • Removed the deprecated fmt/posix.h header that has been replaced with fmt/os.h.

  • Removed the deprecated format_to_n_context, format_to_n_args and make_format_to_n_args. They have been replaced with format_context, format_args and make_format_args respectively.

  • Moved wchar_t-specific functions and types to fmt/xchar.h. You can define FMT_DEPRECATED_INCLUDE_XCHAR to automatically include fmt/xchar.h from fmt/format.h but this will be disabled in the next major release.

  • Fixed handling of the '+' spec...

Read more

7.1.3

25 Nov 14:37
Compare
Choose a tag to compare
  • Fixed handling of buffer boundaries in format_to_n (#1996, #2029).

  • Fixed linkage errors when linking with a shared library (#2011).

  • Reintroduced ostream support to range formatters (#2014).

  • Worked around an issue with mixing std versions in gcc (#2017).

7.1.2

04 Nov 15:39
Compare
Choose a tag to compare
  • Fixed floating point formatting with large precision (#1976).

7.1.1

02 Nov 14:27
Compare
Choose a tag to compare
  • Fixed ABI compatibility with 7.0.x (#1961).

  • Added the FMT_ARM_ABI_COMPATIBILITY macro to work around ABI incompatibility between GCC and Clang on ARM (#1919).

  • Worked around a SFINAE bug in GCC 8 (#1957).

  • Fixed linkage errors when building with GCC's LTO (#1955).

  • Fixed a compilation error when building without __builtin_clz or equivalent (#1968). Thanks @tohammer (Tobias Hammer).

  • Fixed a sign conversion warning (#1964). Thanks @OptoCloud.