Boost logo

Boost Users :

From: John A Meinel (boost_at_[hidden])
Date: 2005-01-18 17:18:42


Yuval Ronen 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.

There actually was a reason. Something about certain functions not
working properly with a const&. Like the std::limits or something like
that. (I ran into this problem because lexical_cast(Parent p) when given
a child will actually create a parent object, so no amount of overriding
virtuals changes things.)

>
> 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
>
Here, I agree with you, but I don't know the rationale at all.

> 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

John
=:->




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