15

I am aware that the c++20 format proposal is a formalization of parts of libfmt, and that libfmt is a compliant implementation of that formalization. However, it's my understanding that libfmt provides additional functionality beyond that specified in the c++20 standard. What are the additional features?

Additional, are the major compiler vendors simply including a subset of libfmt or reimplementing it?

cigien
  • 57,834
  • 11
  • 73
  • 112
Walrus
  • 405
  • 4
  • 10

1 Answers1

25

There are a bunch of things in libfmt that are not in C++20 format:

  • fmt::print() to print directly to stdout.
  • fmt::memory_buffer as basically a dynamically sized container that you could format into via fmt::format_to(buf, ...).
  • Support for formatting ranges and tuples, including fmt::join().
  • Support for named arguments like fmt::print("Elapsed time: {s:.2f} seconds", "s"_a=1.23);
  • Compile-time format strings via FMT_COMPILE, although both fmt::format and C++20's std::format do compile-time format string parsing by default. fmt::format has an escape hook for this named fmt::runtime, std::format has no such hook.

C++23 update: std::print (P2093) and formatting ranges and tuples (P2286) are in C++23.

Barry
  • 286,269
  • 29
  • 621
  • 977
  • 5
    I don't think [`fmt::color` and `fmt::emphasis`](https://godbolt.org/z/d9xxT6) is in C++20 either, but I'd love to be wrong. :-) – Ted Lyngmo Aug 26 '20 at 06:55
  • Does C++20 allow compile-time `string_view` literals as a substitute for `FMT_COMPILE`? – Emile Cormier Jul 13 '21 at 23:03
  • Or put another way, could C++20 implementations perform the same sort of optimizations as `FMT_COMPILE` when a `string_view` literal is passed as the format string? – Emile Cormier Jul 13 '21 at 23:15