Boost logo

Boost :

From: Yuval Ronen (ronen_yuval_at_[hidden])
Date: 2005-01-29 18:16:10


> There was recently another whitespace-with-lexical_cast related question at
> Boost users list, where the poster preferred no whitespace stripping. To
> quote:
>
> --- Start quote ---
>
> From: "Yuval Ronen" <ronen_yuval_at_[hidden]>
> To: <boost-users_at_[hidden]>
> Sent: Saturday, January 15, 2005 5:47 PM
> Subject: [Boost-users] Two issues with lexical_cast
>
> <snip>
>
>>2. lexical_cast ignores trailing whitespaces, but not leading
>>whitespaces. Meaning that
>>
>>int a = lexical_cast<int>("3 "); // three-space
>>
>>will work and return 3, but
>>
>>int a = lexical_cast<int>(" 3"); // space-three
>>
>>will throw. Why? There's no rationale here. Both cases should be treated
>>in the same manner, and IMHO, that manner should be throwing.
>
>
> --- End quote ---

There's nothing more flattering than being quoted, thanks! :-)

> So what should lexical_cast do; strip or not? Ladies and gentlemen, can we
> have your votes? ;)
>
>
>>My question is, why does it do this - as this specifically stops
>>lexical_cast from working with complex types. So could this be an option,
>>or completely disabled, or made an option (somehow) to lexical_cast?
>
>
> Adding options to lexical_cast is difficult. It's meant to resemble regular
> casts, and any additional template- or function-arguments makes it no longer
> look like a cast.

I get the feeling that making it look like a cast is being overrated.
This is clearly a case where there's a real difficulty in determining
what is the most "common", or "natural" way of doing it for most people
(without any intention of weakening my case in the user's list thread,
of course :-) ). So IMHO, the customization's benefits will prove more
important than cast resemblance.


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