Re: [boost] string_to/to_string (was: Re: Report from Berlin C++ Standards Committee meeting)

Olaf van der Spek wrote:
On 4/15/06, Reece Dunn <msclrhd@hotmail.com> wrote:
What about converting to different string types, mainly std::string or std::wstring?
I am also working on implementing to_string and string_to :). Maybe we could combine our efforts and get to_string/string_to into Boost.
At the moment, my versions don't have locale support and string_to isn't returning optional<T>, although I am working on it. They can be used like this:
print( boost::to_string< char >( 10 )); // returns std::string
The template parameter doesn't look nice (IMO). What about to_basic_string<T> and to_string as alias for to_basic_string<char> and to_wstring as alias for to_basic_string<wchat_t>?
What about when you want to have a different character traits or allocator type for the string you are converting to?
But then you're still limited to basic_string. Can't you make one that can use other containers?
Interesting. However, I would say define it as "to_string< StringT >( x ) will convert the object x into a string of type StringT, provided that char_type< StringT >::type returns the underlying string type of StringT and StringT can be constructed from a pointer to that type." This would then allow you to define one for ATL::CStringT< CharT >, QtString or whatever other string type you want to use. You could then use it to do things like: list.AddItem( to_string< ATL::CString >( data.string )); // std::string --> ATL::CString qtlist.AddItem( to_string< QtString >( 10 )); // int --> QtString Without the template, it is difficult to do this. - Reece _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

On 4/16/06, Reece Dunn <msclrhd@hotmail.com> wrote:
The template parameter doesn't look nice (IMO). What about to_basic_string<T> and to_string as alias for to_basic_string<char> and to_wstring as alias for to_basic_string<wchat_t>?
What about when you want to have a different character traits or allocator type for the string you are converting to?
I forgot the other template parameters of basic_string in to_basic_string<T>, but of course they should be there too. The more general approach (to_string< StringT >( x )) would be even better to offer but I still think a simple to_string without template parameters should also be available.
But then you're still limited to basic_string. Can't you make one that can use other containers?
Interesting. However, I would say define it as "to_string< StringT >( x ) will convert the
But then you reintroduced the template parameter.
participants (2)
-
Olaf van der Spek
-
Reece Dunn