Boost logo

Boost :

Subject: Re: [boost] Review Request: Introduction of boost::string, namespace and string-conversion functions
From: Vladimir.Batov_at_[hidden]
Date: 2009-02-16 22:16:13

> That would be:
> string s = boost::string::convert(-1); // to string
> int i = boost::string::convert<int>(str); // from string

Yes, or

string s = boost::string::convert(-1, default_str); // to string
int i = boost::string::convert(str, -1); // 'int' deduced from the second

> And with that we're almost back at the interface of boost::lexical_cast
> once again.

Yes, in fact my very first request was to extend lexical_cast. However, it
was collectively decided to start a separate library to accommodate
formatting, locales, etc.

> Also the user might want to convert between std::wstring and
> std::string, and in C++0x, std::u8string, std::u16string, and
> std::u32string.

Yes, now I am coming to realize that accommodating all that additional
conversion-related functionality is better done without disturbing the
existing lexical_cast.

I am hoping the proposed boost::string::convert() "library" is
sufficiently flexible to accommodate future growth including the
conversions you mentioned. They will be implemented as
specializations/overloads of that same boost::string::convert(). Although
I have a suspicion that std::string<->std::wstring is not such an easy
task. It is because (at present anyway) in my program I do not know if
std::string is, say, UTF8 ot MBCS (which might happen to be UTF8 as on
Linux or might not as on Windows, Solaris). With std::u8string,
std::u16string, and std::u32string it certainly will be easy as we know
what we are converting from/to. So, I suspect it'll be as easy as having

        std::wstring convert(std::u8string)
        std::u8string convert(std::wstring)


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