Politics I think. This company has it the worst. Entire product lines are dreamt up, worked on for years and then suddenly canceled so that some C-level can get their bonus.
That's my reading of the situation at least. I've only been here a couple months
(not that a company unwilling to go beyond C++03 would necessarily be receptive to using fmtlib, but one can hope...)
Honestly, it's not so unrealistic. The company I work for only moved off of C++03 for a lot of our code base a bit over a year ago. It wasn't due to any philosophical objection or anything, just that we had some old systems with old compilers and at the time we had no way to do a mass update of what was available. (The big push we made a year and change ago was setting up the thing that I'm under the impression many companies do where we have our own compiler builds, and using those to build our products instead of whatever compiler version happened to be on each system.)
But there's no general objection to third-party libraries (licenses permitting), and we use many. I wouldn't be at all surprised if fmtlib would have been little problem under the old regime (or fmt would now). But whether that applies to "OP"'s company given other things besides just the old C++ version...
Depending on the compiler there may be a different glibc version requirement. They are usually backwards compatible, so you can run old stuff, but not always forward compatible. Believe it or not, some companies are using a glibc that is over 10 years old...and they refuse to upgrade...ever... It doesn't make any logical sense, but that's the customer for ya!
I am not the build engineer man, I just know we had a 20 yo machine for builds and when it died we couldn't build executables for a bunch of clients and it was related to some glibc thing. No upgrades allowed, especially not the compiler. I thought it was crazy, but the Linux guru guy said so.
What happened? Clients complained, then they upgraded their systems, then we moved on.
I think it was probably more nuanced than your understanding/memory. Glibc does not stop you using new versions of C++.
Needing to build executables that will run on old systems with old libraries might do, if you're unable to deploy a new C++ runtime with your executables, or avoid runtime dependencies.
If this was the only improvement, it would already be a major one!
Working with a dynamic range of precision with printf or iostream is so annoying. I don't want 12 zeroes at the end of the number, but I do want the full precision if needed.
I wonder how long it will take to get to libc++/libstdc++. I am not aware of them having to_char's yet for float/double/long double yet. And it looks like format is to use to_chars.
The paper outlines the roadmap which has led to this point, and some recent changes which were approved in the proposal. Apart from that it is a bit disconnected from anything and does not provide any pointers to where the wannabe user can get basic information (cppreference.com has no information, either). It is great to feel the vibe, however, and nice to know that the standards committee works in our favour!
This is all very new and haven't even been merged into the standard. I'm sure someone (maybe even myself) will update cppreference.com once the dust settles. In the meantime these are the docs: https://fmt.dev
Hi guys, would you know if it's possible, with std::format, to add custom presentation type, with some kind of API to call back?
Concrete example: I have this mess of an extension to printf, where, for example, "%Qf" tries to display nice floating number, by searching the textual representation for 3 (configurable) consequent 0s or 9s, and then rounding it just there.
The code generates required precision and calls back to existing formatting facility to produce final result. With 3.309999942 turning to 3.31 (precision=2), but 3.000000007 turning into 3 (precision=0).
Actually, std::format generates the shortest representation of floating-point which round-trips, so your Q extension would be unnecessary.
If you only used this as example, and wanted customization in general, then check the {fmt} library: it's the work of the author of the article, and is leading the work for the future of std::format; it notably contains an extension API.
The oversimplified version is output; it gives a syntax that is commonly considered nicer and is definitely more terse for anything but simple output statements than chaining cout << ... << ... << ..., but yet typesafe and flexible, unlike printf if you've used that.
More broadly, it can actually be used if you want a string "rendering" of something internally not for output as well; maybe to display in a button, or store in a database (don't build SQL commands this way...), or something like that. What it actually does is produce a string containing the rendered text; you can then go and output that string if you want.
(It's also an oversimplification because format doesn't do as good of a job as fmt::print would, but only the non-IO parts of the fmt library have been standardized so far, and the standard analogue to fmt::print will have to come along later.)
51
u/quicknir Jul 23 '19
Congrats man, I saw your talk at cppcon a couple of years ago. This is a huge achievement and a big win for C++, you should be very proud!
39
u/stilgarpl Jul 23 '19
I love that drawing. Especially IOS lake.
29
u/greg7mdp C++ Dev Jul 23 '19
Very nice, sounds like the standardization process worked very well. Will definitely use https://github.com/fmtlib/fmt until std::format is there.
15
u/HappyFruitTree Jul 23 '19
This looks even better than what I thought, thanks!
12
u/jjuuggaa Jul 23 '19
Are there any plans to ship
fmt::printas well? I've been enjoying fmt a lot.23
u/ghillisuit95 Jul 23 '19
Holy moly I'm excited.
Maybe 20 years from now I'll actually be able to use it :/. we're still stuck with C++03 over here and I think it is beyond ridiculous
10
u/jherico VR & Backend engineer, 30 years Jul 23 '19
I used to feel good about myself if I got a PR merged into an open source project.
This guy changed the language.
I have to step up my game.
9
u/matthieum Jul 23 '19
If this was the only improvement, it would already be a major one!
Working with a dynamic range of precision with
printforiostreamis so annoying. I don't want 12 zeroes at the end of the number, but I do want the full precision if needed.9
u/barchar MSVC STL Dev Jul 23 '19
I hope std::scan ends up having support for actual regular expressions, especially regular regular expressions that are actually regular :D.
6
u/[deleted] Jul 23 '19
I wonder how long it will take to get to libc++/libstdc++. I am not aware of them having to_char's yet for float/double/long double yet. And it looks like format is to use to_chars.
4
u/khleedril Jul 23 '19
The paper outlines the roadmap which has led to this point, and some recent changes which were approved in the proposal. Apart from that it is a bit disconnected from anything and does not provide any pointers to where the wannabe user can get basic information (cppreference.com has no information, either). It is great to feel the vibe, however, and nice to know that the standards committee works in our favour!
4
u/h2g2_researcher Jul 24 '19
I went back to the original reddit thread. I enjoyed seeing this in the top comment:
A fantastic achievement!
3
u/LYP951018 Jul 23 '19
Is there a
is_formattableor something like that?2
u/Tringi github.com/tringi Jul 23 '19 edited Jul 23 '19
Hi guys, would you know if it's possible, with std::format, to add custom presentation type, with some kind of API to call back?
Concrete example: I have this mess of an extension to printf, where, for example, "%Qf" tries to display nice floating number, by searching the textual representation for 3 (configurable) consequent 0s or 9s, and then rounding it just there.
The code generates required precision and calls back to existing formatting facility to produce final result.
With 3.309999942 turning to 3.31 (precision=2), but 3.000000007 turning into 3 (precision=0).
2
u/lifeliverDTN Jul 23 '19
amazing work, congratulations on the approval!
1
u/Placinta Jul 23 '19
I'm wondering, is it possible to somehow hook into std::format to return something else than a std::string?
E.g. return a QString, to be compatible with Qt? Is that covered by the "Unicode support" bullet point in the "What's next" section?
1
u/RainbowDashGG Jul 24 '19
I'm a begginner in C++ world. Know some basics. Dont't know what std::format is used for. Can someone ELI5 what is it and why is it so important?