Boost logo

Boost Users :

From: me22 (me22.ca_at_[hidden])
Date: 2006-12-18 18:05:15


On 12/18/06, Phil Endecott <spam_from_boost_users_at_[hidden]> wrote:
> 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.


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