Boost logo

Boost :

From: Yuval Ronen (ronen_yuval_at_[hidden])
Date: 2007-05-11 05:32:19


Dan Day wrote:
>>> I still think the
>>> semantics of `lexical_cast("127")` should allow for the
>>> conversion to happen -- either convert to a 'short int' then assign to
>>> a char, if that makes any sense.
>
>> There is no way to distinguish int8_t and char. They are both aliases to
>> the same type.
>> Welcome to the wonderful world of typedefs.
>
>
> Maybe I'm just short-sighted, but it seems to me this really isn't a
> problem. A lexical_cast conversion from char * -> char doesn't make much
> practical sense in my mind except for grabbing the first character in the
> string, which can be done numerous other ways. AFAICS, lexical_cast could be
> specialized for char * -> char for such conversions as the OP desires. To
> me, that would be far more useful than the current behavior.

FWIW, I completely agree.

I consider lexical_cast<char>("123") to be silly, and I don't quite care
what the semantics of it are. It might as well not compile at all.
lexical_cast<[u]int8_t>("123") is very useful, and should provide
numeric conversion. The fact the the standard I/O streams behave
differently is, well, unfortunate, but doesn't mean we have to continue
punishing ourselves in lexical_cast also (or in to_string/string_to
which I hope will replace lexical_cast, but that's completely OT).


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk