On 12/18/06, Phil Endecott
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?
Well that will, for example, fail massively if T is a float or a rational or... Some hackery along the lines of if_< is_same< make_unsigned< remove_cv<T>::type >::type, unsigned char
, unsigned int, T > const &val1 = val; might work, but is ugly and would make format depend on mpl.
I'm not convinced that having it act like stringstream and lexical cast is a bad thing. Using a uint8_t in a situation where its numerical value would often be output in textual representation also smells of unnecessary size optimization, to me.