Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2006-04-15 19:53:19

Olaf van der Spek wrote:
> On 4/15/06, Reece Dunn <msclrhd_at_[hidden]> 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!

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