Boost logo

Boost Users :

From: Cory Nelson (phrosty_at_[hidden])
Date: 2005-01-19 00:37:23


For 1, I'm not sure.
For 2, It seems more like a problem with stringstream - I think
lexical_cast does:

stringstream ss;
ss << input;
ss >> output;
return output;

On Sat, 15 Jan 2005 18:47:57 +0200, Yuval Ronen <ronen_yuval_at_[hidden]> wrote:
> Hi.
> I'm probably just another one out of a million who make these remarks,
> but I found nothing in the documentation about them, so I'll mention
> them anyway.
>
> 1. lexical_cast(Source arg) takes the source argument by value. Why not
> by const& ? Calling lexical_cast(some_basic_string) now makes a copy of
> the source argument for no reason.
>
> 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. After a
> look at the code, it seems that the trailing-whitespace-ignore code
> ('stream >> std::ws' in line 151) was specifically added, so there was
> supposed to be a reason for this. But as I said, I believe this is
> wrong, at least as the default behaviour when converting a string to
> something else. Maybe some policies (IgnoreLeadingWhitespace,
> IgnoreTrailingWhitespace) can be added to control this? And again, I
> suppose I'm not the first to think of it...
>
> Thanks,
> Yuval
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Cory Nelson
http://www.int64.org

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