Boost logo

Boost :

From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2004-09-18 07:23:50

>From: "Martin" <adrianm_at_[hidden]>

> I have tried to use lexical_cast many times but I always run into problems
> sooner or later due to the lack of locale support.
> Why not add a locale overload (or default argument) to lexical_cast.
> std::string x = lexical_cast<std::string>(1234); // "1 234" on my PC
> std::string y = lexical_cast<std::string>(1234, std::locale::classic
> ()); // "1234" on my PC
> double xmlDbl1 = lexcal_cast<double>("1.23"); // bad_cast on my PC
> double xmlDbl2 = lexcal_cast<double>("1.23", std::locale::classic());

This issue has come up with quite regular intervals. The current docs says a
little bit about this:

"Where a higher degree of control is required over conversions,
std::stringstream and std::wstringstream offer a more appropriate path."

However, an earlier version of the docs contained more information on

--- Start quote ---

Future directions

- It is also worth mentioning future non-directions: anything that involves
adding extra arguments for a conversion operation is not being considered. A
custom keyword cast, such as lexical_cast, is intended to look like a
built-in cast operator: built-in cast operators take only a single operand.
Where a higher degree of control is required over conversions, the standard
stringstream offers a more appropriate path. Where non-stream-based
conversions are required, lexical_cast is the wrong tool for the job, and so
it won't be special-cased for such scenarios.

--- End quote ---

(Kevlin Henney isn't following the Boost list (at least, he didn't use to).)



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