-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I print a bool? #170
Comments
Thanks for the feedback. Currently fmt::print("{}", true); // will print true (currently prints 1)
fmt::print("{:d}", true); // prints 1 This will be consistent with Python's behavior. What do you think? |
I was expecting to remain consistent with fmt::print("{}", true); // prints 1 (as it currently does)
fmt::print("{:boolalpha}", true); // prints true (new behavior, opt-in) where I like Python's behavior a lot. IMO it is just a tradeoff of "breaking" existing code vs doing the "nice" thing. There is no right solution. As long as there is an easy way to do it I am happy. |
Unary + turns bool to int easily, so bool printing as true/false is the better default. |
@gnzlbg I thought about A more serious concern is breaking expectations of existing code, but this can be mitigated by a configuration option that returns the old behavior for projects that rely on it. In any case, since bool formatting is not documented at all, anyone who used it was using it at their own risk =). @chipdude Thank you for the feedback too. |
Since the project follows semantic versioning, it actually suffices to bump On Sunday, June 7, 2015, Victor Zverovich notifications@github.com wrote:
|
Fixed in 9d09214. This will be in the next release (2.0) since there are other breaking changes that require major version change anyway. |
Thanks! |
I would like to print a C++ bool, such that when it is true it outputs "true", and false outputs "false". I can workaround this with the ternary operator, but it shouldn't be necessary.
There doesn't seem to be anything about this in the syntax docs.
The text was updated successfully, but these errors were encountered: