r/cpp • u/aearphen {fmt} • May 10 '23
{fmt} 10.0 released with more formatters, improved floating point and chrono formatting, modules and more
https://github.com/fmtlib/fmt/releases/tag/10.0.010
u/usefulcat May 12 '23
I see a noticeable performance improvement compared to 9.1 (around 12% in my case). And I didn't see any new warnings or errors. A literal drop-in improvement so far. Well done.
3
73
1
u/sparkyParr0t May 11 '23
Does any of this will get integrated with the <format> std library header at some point ? Is there any STL dev team using fmt under the hood ?
4
u/aearphen {fmt} May 11 '23
Things are being proposed for the standard usually after we get implementation and usage experience in {fmt}. For example, Barry Revzin has done a lot of work on formatting of ranges. I am writing a paper on path formatting. FP improvements are purely QoI and can be done without any proposal.
4
1
u/Ameisen vemips, avr, rendering, systems May 22 '23
It seems like fmt::println doesn't work appropriately with wchar_t, even with the appropriate header. It complains about format conversion. I wasn't able to write my own that worked, either.
-4
u/magnesium_copper May 10 '23
I only use odd number versions. Waiting for 11.
23
u/aearphen {fmt} May 10 '23
odd
-2
u/magnesium_copper May 10 '23
No joke. 5, 7 and 9. I find them more stable.
It seem that even numbers are still deciding what to do with newly added features and odd numbered are like: oh yeah.
Either way, I'll still have to wrap it to reflect newest changes anyways.
Finally, you guys, thank you so much for the work on the lib.
7
u/aearphen {fmt} May 10 '23
> Finally, you guys, thank you so much for the work on the lib.
Credit goes to {fmt} contributors: https://github.com/fmtlib/fmt/graphs/contributors. 46 people contributed to this release alone!
1
u/slk756 Jun 05 '23
I am very confused but somewhat intrigued. Is this just your perception? Is it the fact that sometimes things start with v0 and then get improved in v1 and the cycle continues? Is it the people releasing the versions normally adding more stability to odd versions? Does this phenomenon, if it exists, transfer across languages and areas of the world? I should look into if this is an actual thing
1
4
0
May 10 '23
[deleted]
5
u/aearphen {fmt} May 10 '23
We already went through this for enums which are way more widespread than custom string types. Ideally custom string types should have proper formatters but if it's problematic for some reason adapting is the way to go. Nice thing about
format_asis that it can be provided without adding a dependency on {fmt}.11
u/witcher_rat May 10 '23
As far as I can tell this means that existing types (e.g., custom string types) that have a operator std::string_view() will stop working now.
Yes, I hit that problem immediately when upgrading.
But you don't need to use the
format_as()method - you can just use thefmt::formatterforstd::string_view, without needing to modify the custom type that you're using - just inherit from it:namespace fmt { template<> struct formatter<my_namespace::MyCustomType> : formatter<std::string_view> {}; }Since your custom type implicitly converts to
std::string_view, it will implicitly convert to the argumentsfmt::formatter<std::string_view>'s functions needs as well.
31
u/Nicksaurus May 10 '23
These look like some nice QOL improvements. I'm looking forward to trying this version
So am I right in assuming format_as is now a better option for custom types than specialising fmt::formatter in most cases?
It seems like fmt::formatter is now only necessary if you a) want to avoid creating temporary strings, or b) need custom format string syntax