[format] %d, %u etc. with (unsigned) char types

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[format] %d, %u etc. with (unsigned) char types

Luke Elliott
I couldn't find anything on this in the list archives or the format
docs, but it seems likely to have been asked before so apologies if that
is the case.

I would expect something like:

boost::format fmt("%d");

fmt % char(0);
std::cout << fmt;

to output "0" given that %d is explicitly specified. This isn't the case
  (with VC++ 7.1 and GCC 3.4 at least, and presumably all others given
this is normal stream behaviour).

Obviously it can be worked around by casting to a non-char type, but
that seems a shame given the nature of the library and not having to
worry about type-safety too much.

So, is this by design or accident? If not by design, would it be
possible to change the behaviour (specialisation somewhere for
(unsigned) char types or something??)?

Thanks in advance

Luke Elliott.

Boost-users mailing list
[hidden email]