
David Abrahams wrote:
on Sun Feb 08 2009, Andrey Semashev <andrey.semashev-AT-gmail.com> wrote:
David Abrahams wrote:
That's not my concern. My concern is that I don't think lexical_cast is a particularly good interface for its main uses, which could be thought of as "to-string" and "from-string."
I disagree. lexical_cast was designed to be simple to use, and I think it does it very well. The "to-string" and "from-string" conversions, in their simple form, are just corner cases.
Eh? What other uses has it got?!
If I want to simply parse an int, I don't want to make up a Spirit grammar for that or even use scanf.
scanf is *way* lighter weight that lexical_cast.
I need a C++-style of strtol, which is safe in terms of buffer allocation and types.
So write that.
This is what lexical_cast tries to achieve and it does, to some degree. I don't know of any other tools that come this close to this goal, neither in Boost, nor outside of it.
So write one (just my opinion). lexical_cast means something very strange and overly-general, and we should write something targeted at the real-world uses people actually have.
Perhaps someone could simply implement the C++0x s2* and to_string functions as described in the draft, 21.4 Numeric Conversions? They're pretty trivial, and sufficient for all numeric use cases. They don't work with user-defined types, though. Sebastian