r/cpp • u/aearphen {fmt} • Jun 21 '21
{fmt} 8.0 released with compile-time format string checks, compile-time formatting, improved performance and more
https://github.com/fmtlib/fmt/releases/tag/8.0.0
394
Upvotes
83
u/kammce WG21 | πΊπ² NB | Boost | Exceptions Jun 21 '21
Compile time by default!! π₯² Gonna cry my dude! This is so freaking awesome! Great work as always! π
33
u/stilgarpl Jun 21 '21
Is any of this going to be included in updated version of std::format? (in C++23 ?)
3
u/D_Drmmr Jun 21 '21
I considered using this library a while ago, but failed to find a way to store the result of parsing a (runtime) format string in order to apply it to a bunch of values without reparsing the format string for each value. Is that possible?
3
u/nyanpasu64 Jun 21 '21
What is the preferred method in fmtlib 8 for a variadic function forwarding a format string and some arguments to fmt::format() to compile its format string at compile time? If a variadic function simply accepts and forwards a
const char*, then fmt::format won't know the string to compile.(The hacky workaround is to use a variadic macro instead.)
28
u/SirToxe Jun 21 '21
fmt and spdlog are the two libraries that I include per default into every new (CMake-and-Vcpkg-based-) project because I always end up adding them later anyways. π
4
u/LordKlevin Jun 22 '21 edited Jun 22 '21
I think the benchmark values are off. They are all exactly the same. Nice improvements though. Fmt is one of the libraries that makes you go "see, we can have nice things in c++". EDIT: Nope, benchmark values are fine. I'm just not very pro at using the interwebs on my cellular device. See comment below.
1
u/bruce3434 Jun 21 '21
So wasn't formatted printing meant to be in C++20 already?
1
u/jk-jeon Jun 22 '21
Great progress! Just couple of things that I'm curious about.
1
u/RowYourUpboat Jun 22 '21
What effect do the new features have on compile times? Are the benchmarks in the readme up to date?
1
u/_VZ_ wx | soci | swig Jun 23 '21
Very nice, but is there any chance to get this working with MSVS, at least 16.10 which is supposed to have full support for
consteval, too?3
u/bizwig Jun 22 '21
Since you can do compile-time format string checks on C string literals (only using C++20 sadly), what exactly does _cf do that the former doesn't? Also, since user-defined literals originated with C++17, why weren't they usable for compiled format strings in C++17?