Boost logo

Boost :

Subject: Re: [boost] lexical_cast optimization
From: Mika Heiskanen (mika.heiskanen_at_[hidden])
Date: 2008-12-03 13:35:56

Darren Garvey wrote:
> 2008/12/3 David Abrahams <dave_at_[hidden]>
>> Someone was asking me today about the inefficiency of lexical_cast for
>> its common itoa/atoi-like usage, and it occurred to me that it could
>> *easily* be optimized to handle the common cases by dispatching to
>> itoa/atoi ftoa/atof where available, and even sprintf. Seems like a
>> great idea to me.
> You may find the following interesting:
> I'd quite like to know if Johan got these changes into the library. Any news
> on this?

Please do not proceed at the expense of error handling. I believe using itoa
and ftoa is fine, but using atoi and atof is definitely not:

   cout << atoi("123X") prints 123
   cout << atoi("X") prints 0

lexical_cast<int> throws in both cases, which I think is 100% the correct

--> Mika Heiskanen

Boost list run by bdawes at, gregod at, cpdaniel at, john at