Re: [boost] to_string(v)

Some time ago (2002) there was talk about a to_string function. Did this ever materialize? http://lists.boost.org/Archives/boost/2002/01/23585.php "to_string(5)" is a lot shorter than "lexical_cast<std::string>(5)". Likewise for "to_int("5")". Greetings, Olaf

2011/9/29 Olaf van der Spek <ml@vdspek.org>:
Some time ago (2002) there was talk about a to_string function. Did this ever materialize?
Functions to_string and to_wstring are part of the upcoming C++0x standard. However, there is no to_u16string and to_u32string.
"to_string(5)" is a lot shorter than "lexical_cast<std::string>(5)".
Likewise for "to_int("5")".
As for me, it is easier to remember one function lexical_cast, than tens of of them: stoi, stoll, stof, to_string, to_wstring, stod... Also, it is hard to use those functions in generic programming. Best regards, Antony Polukhin

On Thu, Sep 29, 2011 at 6:46 PM, Antony Polukhin <antoshkka@gmail.com> wrote:
2011/9/29 Olaf van der Spek <ml@vdspek.org>:
Some time ago (2002) there was talk about a to_string function. Did this ever materialize?
Functions to_string and to_wstring are part of the upcoming C++0x standard. However, there is no to_u16string and to_u32string.
But they're not in Boost? Unfortunately I can't use C++11 in some projects for quite some time.
"to_string(5)" is a lot shorter than "lexical_cast<std::string>(5)".
Likewise for "to_int("5")".
As for me, it is easier to remember one function lexical_cast, than tens of of them: stoi, stoll, stof, to_string, to_wstring, stod... Also, it is hard to use those functions in generic programming.
Not every function is a generic function. Olaf

2011/9/29 Olaf van der Spek <ml@vdspek.org>:
But they're not in Boost? Unfortunately I can't use C++11 in some projects for quite some time.
Well, here is the deal. I write to boost mailing list to check interest in those functions. If there will be some more interested, I`ll add those functions to lexical_cast library or to a separate header/library. OK? Best regards, Antony Polukhin

On Fri, Sep 30, 2011 at 6:01 AM, Antony Polukhin <antoshkka@gmail.com> wrote:
2011/9/29 Olaf van der Spek <ml@vdspek.org>:
But they're not in Boost? Unfortunately I can't use C++11 in some projects for quite some time.
Well, here is the deal. I write to boost mailing list to check interest in those functions. If there will be some more interested, I`ll add those functions to lexical_cast library or to a separate header/library.
OK?
That'd be great.

On Thu, 2011-09-29 at 20:46 +0400, Antony Polukhin wrote:
2011/9/29 Olaf van der Spek <ml@vdspek.org>:
Some time ago (2002) there was talk about a to_string function. Did this ever materialize?
Functions to_string and to_wstring are part of the upcoming C++0x standard. However, there is no to_u16string and to_u32string.
"to_string(5)" is a lot shorter than "lexical_cast<std::string>(5)".
Likewise for "to_int("5")".
As for me, it is easier to remember one function lexical_cast, than tens of of them: stoi, stoll, stof, to_string, to_wstring, stod... Also, it is hard to use those functions in generic programming.
Best regards, Antony Polukhin
Instead of a static set of functions each named to indicate the conversion how about wrapping the destination value with a helper class that can generically convert a string into the value? Something something like the example below. --glenn <example begins> template <class T> class strtoT; // quick non-generic conversion example for int template <> class strtoT<int> { int& t; public: strtoT(int &_t) : t(_t) { } const std::string& operator=(const std::string& s) { t = atoi( s.c_str() ); } }; template<class T> strtoT<T> from_string(T& v) { return strtoT<T>(v); } int main( ) { int val=0; from_string(val) = std::string("456"); std::cout << val << std::endl; }
participants (3)
-
Antony Polukhin
-
Olaf van der Spek
-
Schrader, Glenn - 1002 - MITLL