Boost logo

Boost Users :

From: Phil Endecott (spam_from_boost_users_at_[hidden])
Date: 2006-12-18 17:42:08


>> This does what I want:
>>
>> uint8_t i = 65;
>> printf("i = %d\n",i);
[snip]
>> uint8_t i = 65;
>> cout << boost::format("i = %d\n") % i;
>>
>> But it seems to have the same, unwanted, behaviour as cout<<i.
[snip]
>> At the moment I have to write things like
>>
>> cout << "i = " << static_cast<unsigned int>(i) << "\n";>

> You can just cast the value to an int

Yes, as I mentioned towards the end of my message. But I find that
obfuscated. It's particularly problematic when the value is a field in
a struct whose type I don't exactly remember, and I forget the need to
cast it; the result is control characters being written to the
terminal, which can be hard to debug.

Surely, since I have asked for %d in the format string, format() can do
the cast? i.e. something like (PSEUDOCODE)

template <typename T>
operator%(T val) {
   ....
   if (format_char='d')
     int val1 = static_cast<int>(val)
   ...
}

or have I missed some additional complexity?

Phil.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net