I was happy for the standard library to get a to_string function, but now I’m in WTF mode. First of all why isn’t this templated, second of all if it is not a template on return value then why in the world they don’t have to_u16string() and to_u32string() functions.
I know that there is boost lexical cast, but I’m curious to know if there is a standard way to get what I want without manually writing these functions?
EDIT: to make matters worse boost 1.46 also dislikes u16string 🙁
boost::lexical_cast<u16string>(22.44);
terminate called after throwing an instance of
‘boost::exception_detail::clone_impl‘ what(): bad lexical cast: source type value could not be interpreted as target
Relax and take a deep breath before you collapse.
It all makes perfect sense.
to_stringandto_wstringusesprintf/wsprintf. There is nothing in the language that crosses the bridge between agnostic narrow/wide encoding and the UTF encodings, so there simply does not exist a standard library facility to produce UTF-encoded strings. The new UTF-facilities allow you to store UTF-encoded strings and transcode among them, but there is no way to encode a system-specific encoding to a UTF-encoding without the help of an extra library.How would those “20 lines of code” look like that you propose? Include floating point numbers, please.
(Here are my standard question links on the subject: #1, #2, #3)