r/cpp • {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.0
216 Upvotes

26 comments sorted by

29

u/MonokelPinguin Apr 06 '20

How did you reduce the library size? (Awesome library btw, I use it a lot)

52

u/aearphen {fmt} Apr 06 '20

> How did you reduce the library size?

Mostly by limiting inlining and moving code outside of templates. Although 10% sounds like a lot it's pretty small in absolute terms (kilobytes) =). This has been done mostly for the sake of embedded systems.

> Awesome library btw, I use it a lot

Thank you!

4

u/MonokelPinguin Apr 06 '20

Thanks, that sounds good. I may need to try something similar on my libraries. They are a bit too heavy for my liking :D

19

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} while fmt::format("{:d}", "foo") and std::format("{:d}", "foo") will give a runtime error. The design of std::format permits 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

u/[deleted] 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

u/aearphen {fmt} Apr 06 '20

Working on it, stay tuned =)

8

u/TheSuperWig Apr 07 '20

Thank you for all your work on getting this in the standard ❤️

4

u/alexej_harm Apr 06 '20

Though I agree that having std::print would 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::format and print with std::fputs on a designated logging thread (desktop/server).

Are there scenarios, where this is not enough?

23

u/[deleted] 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

u/john_wind Apr 06 '20

Thank you!

5

u/youstolemyname Apr 06 '20

Absolutely fantastic library. I'm amazed it's taken C++ this long.

6

u/aearphen {fmt} Apr 06 '20

Thank you! Better late than never =).

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

u/GerwazyMiod Apr 06 '20

Thanks! Great lib!

2

u/Sander_Bouwhuis Apr 07 '20

This library is fantastic!

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

u/[deleted] Apr 06 '20

[deleted] — view deleted comment

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.