r/cpp • u/aearphen {fmt} • Apr 06 '20
{fmt} 6.2 released with improved error reporting, smaller library size, better compatibility with std::format and more
https://github.com/fmtlib/fmt/releases/tag/6.2.019
u/The_Northern_Light Apr 06 '20
Maybe this isn't the right place to ask, but what are the biggest / best parts of {fmt} that didn't make it into std::format()? Once I have std::format(), when would I still reach for {fmt}?
20
u/aearphen {fmt} Apr 06 '20
Some of the features are I/O, compile-time checks, named arguments, color.
4
u/hak8or Apr 06 '20
compile-time checks
Wait wait, hold on a second right there. Really? Can you provide an example or two showing what would pass in std::format but fail in fmt?
21
u/aearphen {fmt} Apr 06 '20
fmt::format(FMT_STRING("{:d}"), "foo")will give a compile-time error in {fmt} whilefmt::format("{:d}", "foo")andstd::format("{:d}", "foo")will give a runtime error. The design ofstd::formatpermits compile-time checks so we can add them in the future with a more reasonable API than the current macro-based one in {fmt} which is mostly due to compatibility reasons (it works with C++14).13
u/James20k P2005R0 Apr 06 '20
color
I didn't know there was a fmt version with colour, one of the aims of the colour proposal I'm working on is to provide something for std::format to work with, ill have to have a look at this tomorrow!
17
Apr 06 '20 edited Apr 06 '20
Since C++23 meetings are now on the way (although I think the most recent one was delayed), would it be a good idea for someone (i.e. /u/aearphen) to propose std::print()?
31
4
u/alexej_harm Apr 06 '20
Though I agree that having
std::printwould be very good, I don't see an urgent need for it.If performance is an issue, you either don't print (embedded), or use
std::formatand print withstd::fputson a designated logging thread (desktop/server).Are there scenarios, where this is not enough?
23
Apr 06 '20
Just for convenience sake, it would be nice if we could get rid of those wretched iostreams and idiomatic C++ would look like:
std::print("Hello, {}!", "world");Which is much easier to write than:
std::fputs(std::format("Hello, {}!", "world"));Or some weird mixture of the two:
std::cout << std::format("Hello, {}!", "world");13
u/alexej_harm Apr 07 '20
I totally agree, though it's much worse.
std::fputs(std::format("Hello, {}!", "world").data(), stdout);With some libraries, it's a bit easier.
spdlog::info("Hello {}", "world");
5
u/john_wind Apr 06 '20
FMT_USE_WINDOWS_H was retired???
17
u/aearphen {fmt} Apr 06 '20
It was ineffective for a while now and was removed to avoid confusion. `windows.h` is never included if you use {fmt} as a static or shared library.
6
5
5
u/cleroth Game Developer Apr 06 '20
Did compile times improve? I recently updated to a newer version of fmt and saw my compile times drop by like 5% :(
10
u/aearphen {fmt} Apr 06 '20
There was some improvement to compile times in 6.1, but not in this version. Make sure to use `fmt/core.h` whenever possible.
6
u/beautiful_tango Apr 06 '20
Great, it's one of my go-to library, even if I just want to experiment on a small thing, I'd like to use it over the standard stream APIs.
I might use the dynamic arg store for user customization points.
2
2
2
u/strike-eagle-iii Apr 13 '20
I don't think fmt partially making it into C++20 has gotten the praise it really deserves. It is unbelievably awesome. ostreams need to die. now.
0
Apr 06 '20
[deleted]
12
u/aearphen {fmt} Apr 06 '20
Yeah, errors were a bit unwieldy in 6.1 because compilers like to list all the overloads. Now they should be much more readable.
29
u/MonokelPinguin Apr 06 '20
How did you reduce the library size? (Awesome library btw, I use it a lot)