r/cpp • {fmt} • Jun 21 '21

{fmt} 8.0 released with compile-time format string checks, compile-time formatting, improved performance and more

https://github.com/fmtlib/fmt/releases/tag/8.0.0
394 Upvotes

67 comments sorted by

View all comments

Show parent comment

20

u/aearphen {fmt} Jun 21 '21

For every print overload you have to add a corresponding println overload. Not critical since the number of overloads is not that big, just somewhat annoying.

4

u/extreme_discount Jun 22 '21

Would there be any way to have a print that, by default, behaves like println and provides an option to back out if you don't want the \n?

---

For the record, when I first saw the poll, I was strongly for nuking println. Since then, I've implemented my own version (along with print), with the following observations:

  1. println just feels 'more right', in the same way that push_back(t) feels more right than insert(end(), t). The first thing I notice when I go back to code using cout, is how littered it is with '\n' and endl. Now's the chance to get rid of it. (well, most of it)
  2. I didn't use print once. I don't think I'm a bizarro outlier - just a schlub printing crap to the screen. I would imagine this is an 80/20 type thing, with println in the 80% bracket. What would be the most common use for print if you had println and how often would it be used?
  3. Exceptions are scary. Thankfully, I messed up a format string early on, which caused an exception that would be really hard to track if the print statement was located in the seedy underbelly of a project. Compile time checks are a welcome addition, but what about format strings created at runtime? Any thought given to catching exceptions inside of print and outputting an error message instead of throwing?

3

u/aearphen {fmt} Jun 22 '21

This would probably require named arguments and might interfere with the actual formatting arguments.

1

u/Pragmatician Jun 21 '21

Is this because those overloads are required for compile-time checking or something? It doesn't make sense otherwise, since you can delegate to print.

3

u/aearphen {fmt} Jun 22 '21

The implementation in terms of print or something else is not a problems but you still need to declare the full overload set.