Boost logo

Boost :

Subject: Re: [boost] Checking interest in to_string functions
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2011-09-30 12:54:48

Antony Polukhin wrote:
> As was mentioned in `[boost] to_string(v)`
> 1) Functions to_string and to_wstring are part of the upcoming
> C++0x standard. However, there are no functions for char16_t
> and char32_t conversions.
> 2) Some users can't use C++11 in some projects for quite some
> time, but can use boost.
> 3) "to_string(5)" is a lot shorter than
> "lexical_cast<std::string>(5)". Some users would like to use a
> shorter form.
> Is there interest in stoi, stoll, stof, to_string, to_wstring,
> to_u16string, stod and other functions for char, wchar_t,
> char16_t and char32_t conversions?
> Shall I add them to lexical_cast library, or as a separate
> conversion library?

I think it is reasonable to capture to_string() as a standard, extrinsic function template that returns a std::string from T. Each T must supply a specialization that does the right thing, of course, and there would be implementations for built-in types. This means the mechanism is extensible to UDTs. Obviously, to_string<T>(T const &) isn't flexible. It just provides a quick-and-dirty conversion.

I have no idea whether to_wstring(), to_u16string(), etc. would be useful. I've heard too many conflicting things about which string types work or don't for Unicode, etc., and have no firsthand experience.

stoi(), stoll(), stof(), stod() seem less useful, though providing a portable C++03 implementation wouldn't be bad. I don't know how those functions in C++11 compare to functions like strtod(), but that one in particular is painful to use correctly because of the error semantics. I generally wrap such functions behind a function template interface to simplify usage, select the right function for the type being converted, and throw exceptions or return bool on failure.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer using std::disclaimer;
Dev Tools & Components
Susquehanna International Group, LLP


IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

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