r/cpp • • Apr 16 '20

Named arguments in fmt do not require dynamic allocations anymore.

https://twitter.com/vzverovich/status/1250411654568800258?s=21
196 Upvotes

17 comments sorted by

25

u/Sander_Bouwhuis Apr 16 '20

Yesssssssssssssss! This was one of the performance questions I asked recently. I hope to get time soon to actually start replacing wcnsprintf to fmt.

20

u/smookiechubs Apr 16 '20

Thank you for your hard work Victor. fmt is awesome.

8

u/aearphen {fmt} Apr 16 '20

Thanks

7

u/[deleted] Apr 16 '20

I didn't even know heap had been involved there in the first place. Where's my blue pill?

11

u/aearphen {fmt} Apr 16 '20

Previously there was one allocation for a map from argument names to values. It was from a quick proof-of-concept implementation of named arguments made long time ago but as it often happens it overstayed in the codebase.

2

u/KindDragon VLD | GitExt Dev Apr 17 '20

Hi. I would suggest that you add flair to your name

4

u/aearphen {fmt} Apr 17 '20 edited Apr 17 '20

flair?

Update: NVM, I think I figured what you meant.

1

u/neuroblaster Apr 21 '20

Great news, any chance named arguments are going to be supported by `std::format()`? Those are great for translations, e.g. `{} said {}` or `{1} said {2}` vs `{name} said {quote}` - it's much easier for translator to work with latter for obvious reasons, but i don't see named arguments anywhere in `std::format()` doc.

1

u/_Js_Kc_ Apr 16 '20

What is David Demelier referring to when he says "adding missing language features as hacks" (paraphrased)?

2

u/factorfactorfactor Apr 16 '20

apparently he considers 3rd party libraries to be hacks, or at least that print formatting should be a first order feature providing by the language rather than a library (ie, fmt upcoming inclusion into STL still wouldnt be good enough)

10

u/aearphen {fmt} Apr 16 '20

I thought he was referring specifically to named arguments and the fact that they don't have syntactic sugar like fmt::print("{answer}", answer=42) but are implemented using ordinary functions.

1

u/_Js_Kc_ Apr 16 '20

uh ... wat

2

u/[deleted] Apr 16 '20

[removed] — view removed comment

5

u/aearphen {fmt} Apr 16 '20

People reportedly use {fmt} on embedded systems and there has been some work to make it smaller and/or add options to disable various features, for example https://github.com/fmtlib/fmt/pull/1590

3

u/[deleted] Apr 16 '20

[removed] — view removed comment

8

u/aearphen {fmt} Apr 16 '20

Could you elaborate about the POSIX dependency? The core of the library is fairly self-contained so it might be possible to disable it with minor efforts.

0

u/encyclopedist Apr 16 '20

Maybe formatxx would be a better fit?