Topic: Overloading std::to_string() with std::string and std::wstring.
Author: turbine1991@gmail.com
Date: Sun, 11 May 2014 23:57:18 -0700 (PDT)
Raw View
------=_Part_4223_4788648.1399877838187
Content-Type: text/plain; charset=UTF-8
You may be wondering why would anyone want to convert a string into a
string? Story short, generic type handling.
Currently the ways to handle this are any of these when suitable:
- Create a template function for handling the conversion of all types
through std::to_string and then overload string to just return itself. Then
call this function instead of std::to_string().
- Specialise template class methods by overloading different types with
suitable methods.
- Put the characters through a std::stringstream, which is fair bit
slower.
Benefits:
- The conversion using std::wstring and vice-versa handled transparently.
- Use of std::to_string used in generic type conversions, instead of
creating yet another implementation for something so mundane.
I hope you have a good day.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_4223_4788648.1399877838187
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">You may be wondering why would anyone want to convert a st=
ring into a string? Story short, generic type handling.<div><br></div><div>=
Currently the ways to handle this are any of these when suitable:</div><div=
><ul><li><span style=3D"line-height: normal;">Create a template function fo=
r handling the conversion of all types through std::to_string and then over=
load string to just return itself. Then call this function instead of std::=
to_string().</span></li><li><span style=3D"line-height: normal;">Specialise=
template class methods by overloading different types with suitable method=
s.<br></span></li><li><span style=3D"line-height: normal;">Put the characte=
rs through a std::stringstream, which is fair bit slower.</span></li></ul><=
div>Benefits:</div></div><div><ul><li><span style=3D"line-height: normal;">=
The conversion using std::wstring and vice-versa handled transparently.</sp=
an></li><li><span style=3D"line-height: normal;">Use of std::to_string used=
in generic type conversions, instead of creating yet another implementatio=
n for something so mundane.</span></li></ul><div>I hope you have a good day=
..</div></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_4223_4788648.1399877838187--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Mon, 12 May 2014 00:08:42 -0700
Raw View
Em dom 11 maio 2014, =E0s 23:57:18, turbine1991@gmail.com escreveu:
> - The conversion using std::wstring and vice-versa handled transparent=
ly.
That will be most welcome. Using mbstowcs is quite annoying.
--=20
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
.
Author: turbine1991@gmail.com
Date: Mon, 12 May 2014 01:38:15 -0700 (PDT)
Raw View
------=_Part_385_13111202.1399883895907
Content-Type: text/plain; charset=UTF-8
On Monday, 12 May 2014 19:08:42 UTC+12, Thiago Macieira wrote:
>
> That will be most welcome. Using mbstowcs is quite annoying.
>
There's std::wstring_convert available, you may want to use that rather
than the c function mbstowcs. It does require C++11 though.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_385_13111202.1399883895907
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Monday, 12 May 2014 19:08:42 UTC+12, Thiago Macieira w=
rote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8e=
x;border-left: 1px #ccc solid;padding-left: 1ex;">That will be most welcome=
.. Using mbstowcs is quite annoying.<br></blockquote><div><br></div><div>The=
re's <span class=3D"pln" style=3D"font-family: Consolas, Menlo, Monaco=
, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera =
Sans Mono', 'Courier New', monospace, serif; white-space: inherit; backgrou=
nd-color: transparent; color: rgb(0, 0, 0); font-size: 14px; line-height: 1=
7.804800033569336px;">std</span><span class=3D"pun" style=3D"font-family: C=
onsolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans M=
ono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-sp=
ace: inherit; background-color: transparent; color: rgb(0, 0, 0); font-size=
: 14px; line-height: 17.804800033569336px;">::</span><span class=3D"pln" st=
yle=3D"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation =
Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monos=
pace, serif; white-space: inherit; background-color: transparent; color: rg=
b(0, 0, 0); font-size: 14px; line-height: 17.804800033569336px;">wstring_co=
nvert available, you may want to use that rather than the c function mbstow=
cs. It does require C++11 though.</span> </div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_385_13111202.1399883895907--
.
Author: Jim Porter <jvp4846@g.rit.edu>
Date: Mon, 12 May 2014 15:45:07 -0700 (PDT)
Raw View
------=_Part_2696_13902833.1399934707488
Content-Type: text/plain; charset=UTF-8
On Monday, May 12, 2014 1:57:18 AM UTC-5, Chris Ridgway wrote:
>
> You may be wondering why would anyone want to convert a string into a
> string? Story short, generic type handling.
>
I've done similar things with homegrown stringification functions, and I
agree that this is pretty useful.
I'm a bit less convinced of the use of converting std::wstring to
std::string via std::to_string(), but that's more because I think wstring
is a bit of a mess. Fixing that would probably be a long and difficult
process, though.
- Jim
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_2696_13902833.1399934707488
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Monday, May 12, 2014 1:57:18 AM UTC-5, Chris Ridgway wr=
ote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">You may b=
e wondering why would anyone want to convert a string into a string? Story =
short, generic type handling.</div></blockquote><div><br>I've done similar =
things with homegrown stringification functions, and I agree that this is p=
retty useful.<br><br>I'm a bit less convinced of the use of converting std:=
:wstring to std::string via std::to_string(), but that's more because I thi=
nk wstring is a bit of a mess. Fixing that would probably be a long and dif=
ficult process, though.<br><br>- Jim<br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_2696_13902833.1399934707488--
.
Author: Chris Ridgway <turbine1991@gmail.com>
Date: Mon, 12 May 2014 17:02:47 -0700 (PDT)
Raw View
------=_Part_4813_13533057.1399939367776
Content-Type: text/plain; charset=UTF-8
On Tuesday, 13 May 2014 10:45:07 UTC+12, Jim Porter wrote:
>
> I'm a bit less convinced of the use of converting std::wstring to
> std::string via std::to_string(), but that's more because I think wstring
> is a bit of a mess. Fixing that would probably be a long and difficult
> process, though.
>
Don't think of it converting a data type to just a string, it's the
std::generic_string<char> after all which could be used to convert
std::string into std::wstring. It'd certainly be a logical step, although
the character encoding support is quite a mess as you say.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_4813_13533057.1399939367776
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, 13 May 2014 10:45:07 UTC+12, Jim Porter wrote=
:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bo=
rder-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>I'm a b=
it less convinced of the use of converting std::wstring to std::string via =
std::to_string(), but that's more because I think wstring is a bit of a mes=
s. Fixing that would probably be a long and difficult process, though.<br><=
/div></div></blockquote><div><br></div><div>Don't think of it converting a =
data type to just a string, it's the std::generic_string<char> after =
all which could be used to convert std::string into std::wstring. It'd cert=
ainly be a logical step, although the character encoding support is quite a=
mess as you say.</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_4813_13533057.1399939367776--
.