Boost logo

Boost Users :

From: Yuval Ronen (ronen_yuval_at_[hidden])
Date: 2005-01-15 11:47:57


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 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