What are the differences between libfmt and std::format?

Viewed 2268

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?

1 Answers

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

  • fmt::print() to print directly to stdout. This is proposed in P2093. fmt::printf() also exists but is not proposed in that paper.
  • 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
Related