The format library has just been confirmed for
C++20. It handles booleans as you require.
However, on a semantic note the strings "true"
and "false" are rarely applicative to the actual meaning the
bool represents, and as such the easy approach of adding it
directly into a string will rarely be useful.
Hi Garrett
Many thanks for your reply.
Yes, I see std::boolalpha sets an I/O flag.. but seems
a bit of a long way to get it into a string, I'd need
to use in conjunction with std::istringstream to get a
string...
I wanted to do something like this example:
Idea
std::string fmt(const std::string header, bool b)
{
return header + " " + std::to_string(b) + " set";
}
How I would do now
As his doesn't work, I'd have it at present as:
std::string fmt(const std::string header, bool b)
{
return header + " " + b?"true":"false" + " set";
}
Regards, Jonny
On
20/07/2019 21:21, Garrett May via Std-Proposals wrote:
std::boolalpha is already available:
int main(){
bool const a = true;
std::cout <<
std::boolalpha << a << std::endl;
}
My gut instinct here is that one is
supposed to control how one wants data to be
printed out, in the same way as how float/double
precision is done.
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
http://lists.isocpp.org/mailman/listinfo.cgi/std-proposals