Boost logo

Boost Users :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2005-01-18 17:22:03

> 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 numerous optimization/enhancements that could be done to lexical_cast.
In my version I use different interpretators, type wrappers, specializations
e.t.c. And still in my recent study I found that lexical_cast ~ 20 times
slower then sprintf and ~200 times slower then my own handcrafted version
for decimal integer parcing. Conclusion: do NOT use lexical_cast in
performance critical (even performance aware) parts of your code. The only
place where I use it is during initialization. Accordingly no need to bother
about reverence vs. value semantic.

> 2. lexical_cast ignores trailing whitespaces, but not leading
> whitespaces. Meaning that

My recomendation is: trim the value on both sodes before cast. And do not
rely on lexical cast to detect your whitespaces.

> Thanks,
> Yuval



Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at