Topic: join/split for string & string_view
Author: lnaltidev@gmail.com
Date: Sun, 25 Dec 2016 02:32:44 -0800 (PST)
Raw View
------=_Part_692_185115314.1482661964283
Content-Type: multipart/alternative;
boundary="----=_Part_693_1064309226.1482661964284"
------=_Part_693_1064309226.1482661964284
Content-Type: text/plain; charset=UTF-8
Hello,
Most of modern language (D, Python, Java, C#, Go, Rust) got a split method
on their string type, so I think it really make sense to have something
similar in C++.
All of them returns a 'vector' and I think is the main waited result. Allow
users to handle it with random access operator.
I think it should not be required to mastering all subtilities of the STL
to do something a simple as that.
I think it should be possible to write :
auto MyResult= "my,csv,line"s.split(",");
myvar=MyResult[1];
for(auto sv : MyResult)
In my initial proposal on Github, I've used template which allows select
both the target container and the fact of use string or string_view as
result
In this form it's ok
template<class T >
void split(const basic_string& Separator, T &Result)
, but it makes the usage pretty heavy with this form
template<class T >
T explode(const basic_string& Separator)
as it requires to specify the target type in the method call, I agree that
hardcode the choice would be a good option, as it's really not useful to
return something else than a vector.
Returning a string_view sounds me the best compromise for
performance/memory usage, even if there's a risk for having invalid data in
it when used from a temporary string.
Perhaps having multiple (like for stoi,l,ll) could be an option
split(sep,generic_output_container) ==> void
splits ==> vector<string>
splitsv ==> vector<string_view>
splitr ==> range
spliti ==> iterator like boost tokenizer class mentionned by Mikhail
splitr and spliti will probably be a bit complex to specify and to reach a
consensus (personally i'm not yet familiar with range so I can't contribute)
split,splits,splisv would perhaps be more consensual and simple and could
perhaps be part of C++ 17.
@magnus
join purpose is to allow concatenate with a separator inserted (or not if
empty string used)
string::join(vector<string>({ "C++","is","fun!" }), " ")
==>"C++ is fun"
join is not a revolutionary proposal, it's just I consider that it should
be easy to do such a basic stuff in C++ 17 as it's available in most of the
modern languages for years.
Laurent
--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d8544b44-9ed4-403d-a980-6dda516933f6%40isocpp.org.
------=_Part_693_1064309226.1482661964284
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><p>Hello,</p><p><br>Most of modern language (D, Python, Ja=
va, C#, Go, Rust) got a split=20
method on their string type, so I think it really make sense to have someth=
ing=20
similar in C++.<br>All of them returns a 'vector' and I think is th=
e main waited=20
result. Allow users to handle it with random access operator.=C2=A0</p><p>I=
think it should=20
not be required to mastering all subtilities of the STL to do something a s=
imple=20
as that.</p>
<p>I think it should be possible to write :</p>
<div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); b=
order-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; wo=
rd-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettypr=
int"><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">MyResult</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;=
" class=3D"styled-by-prettify">"my,csv,line"</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">s</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">split</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #080;" class=3D"styled-b=
y-prettify">","</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>myvar</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">=3D</span><span style=3D"color: #606;" class=3D"styled-by-prettify">M=
yResult</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[</=
span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">];</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> <br></span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">for</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> sv </span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">MyRe=
sult</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> <br></span></d=
iv></code></div><p>In my initial proposal on Github, I've used template=
which allows select both=20
the target container and the fact of use string or string_view as result</p=
>
<p>In this form it's ok </p>
<div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); b=
order-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; wo=
rd-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettypr=
int"><span style=3D"color: #008;" class=3D"styled-by-prettify">template</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">class</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> T </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">></span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> split</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">const</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> basic_string</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Sepa=
rator</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> T </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&</span><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">Result</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><p>, bu=
t it makes the usage pretty heavy with this form</p>
<div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); b=
order-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; wo=
rd-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettypr=
int"><span style=3D"color: #008;" class=3D"styled-by-prettify">template</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">class</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> T </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">></span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"><br>T explode</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> basic_string</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Separator</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span></div></code></div><p>as it requires to specify the target =
type in the method call, I agree that=20
hardcode the choice would be a good option, as it's really not useful t=
o return=20
something else than a vector. </p>
<p><br></p><p>Returning a string_view sounds me the best compromise for per=
formance/memory=20
usage, even if there's a risk for having invalid data in it when used f=
rom a=20
temporary string.</p>
<p><br></p><p>Perhaps having multiple (like for stoi,l,ll) could be an opti=
on</p>
<p>split(sep,generic_output_container) =3D=3D> void=C2=A0 </p>
<p>splits =3D=3D> vector<string></p>
<p>splitsv =3D=3D> vector<string_view></p>
<p>splitr =3D=3D> range</p>
<p>spliti =3D=3D> iterator like boost tokenizer class mentionned by Mikh=
ail </p>
<p>splitr and spliti will probably be a bit complex to specify and to reach=
a=20
consensus (personally i'm not yet familiar with range so I can't co=
ntribute)</p>
<p>split,splits,splisv would perhaps be more consensual and simple and coul=
d=20
perhaps be part of C++ 17.</p>
<p><br></p><p>@magnus </p>
<p>join purpose is to allow concatenate with a separator inserted (or not i=
f=20
empty string used)</p>
<p></p><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, =
250); border-color: rgb(187, 187, 187); border-style: solid; border-width: =
1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">strin=
g</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">join</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">vector</span><span style=3D"colo=
r: #080;" class=3D"styled-by-prettify"><string></span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">({</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" cla=
ss=3D"styled-by-prettify">"C++"</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">,</span><span style=3D"color: #080;" class=
=3D"styled-by-prettify">"is"</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">,</span><span style=3D"color: #080;" class=3D"s=
tyled-by-prettify">"fun!"</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">}),</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">=
" "</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">)</span></div></code></div><p></p><p>=3D=3D>"C++ is fun"<br=
>join is=C2=A0not a revolutionary proposal, it's just I=20
consider that it should be easy to do such a basic stuff in C++ 17 as it=
9;s=20
available in most of the modern languages for years.</p><p><br></p><p>Laure=
nt</p></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/d8544b44-9ed4-403d-a980-6dda516933f6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d8544b44-9ed4-403d-a980-6dda516933f6=
%40isocpp.org</a>.<br />
------=_Part_693_1064309226.1482661964284--
------=_Part_692_185115314.1482661964283--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 25 Dec 2016 07:41:44 -0800 (PST)
Raw View
------=_Part_687_533956310.1482680504223
Content-Type: multipart/alternative;
boundary="----=_Part_688_969289153.1482680504224"
------=_Part_688_969289153.1482680504224
Content-Type: text/plain; charset=UTF-8
On Sunday, December 25, 2016 at 5:32:44 AM UTC-5, lnal...@gmail.com wrote:
>
> Hello,
>
>
> Most of modern language (D, Python, Java, C#, Go, Rust) got a split method
> on their string type, so I think it really make sense to have something
> similar in C++.
>
All of those languages also only have a single string type. C++ has
*hundreds*. Even the *standard library* has 2, and that doens't even count
`const char*`.
Having a `split` function that can *only* be used with the standard library
string types is pathetic. Especially when it could be made to be used with
any string type (that provides a conversion to `string_view`) with ease.
If you want to suggest that `basic_string` and `string_view` should have
member versions that call the non-member algorithms, fine. But the
non-member function is where the actual work happens.
> All of them returns a 'vector' and I think is the main waited result.
>
No.
While we should not be ignorant of what other languages are doing, we also
should not pretend that the design of other languages is a priori correct
for C++. We should do what is best for C++.
And one principle of C++ is that we do not make people pay for features
they don't need to use. Forcing the return of a `vector` makes people pay
for memory allocations that they may not use.
I think it should not be required to mastering all subtilities of the STL
> to do something a simple as that.
>
Master the subtleties of what? Of using a range? That should be an early
lesson for C++ programmers; it's hardly deep metaprogramming magic.
If you're going to be able to work in a language, you *need* to know its
idioms. And ranges are very important idioms in C++. We shouldn't cater to
the demographic of people who learn just the syntax of a language and then
pretend that they know it.
I think it should be possible to write :
> auto MyResult= "my,csv,line"s.split(",");
> myvar=MyResult[1];
> for(auto sv : MyResult)
>
>
Here is what that code would look like under the guidelines I (and others)
outlined previously:
vector MyResult(split("my,csv,line", ","));
myvar = MyResult[1];
for(auto sv : MyResult)
See how simple that is? This only allocates memory in `vector`'s
constructor (so you're not needlessly allocating a `basic_string`, just for
a string literal).
Plus, if you just want the iteration, without the need for random access:
for(auto sv : split("my,csv,line", ","))
This performs *zero* memory allocations. Why *shouldn't* this be the
default? In C++, the default ought to be fast, where possible.
Perhaps having multiple (like for stoi,l,ll) could be an option
>
No. A single function returning a range, as outlined above, can cover all
of these cases effectively.
--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/172d08f0-a3da-4b9e-bfdd-985fb1f527c8%40isocpp.org.
------=_Part_688_969289153.1482680504224
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Sunday, December 25, 2016 at 5:32:44 AM UTC-5, lnal...@=
gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"lt=
r"><p>Hello,</p><p><br>Most of modern language (D, Python, Java, C#, Go, Ru=
st) got a split=20
method on their string type, so I think it really make sense to have someth=
ing=20
similar in C++.<br></p></div></blockquote><div><br>All of those languages a=
lso only have a single string type. C++ has <i>hundreds</i>. Even the <i>st=
andard library</i> has 2, and that doens't even count `const char*`.<br=
><br>Having a `split` function that can <i>only</i> be used with the standa=
rd library string types is pathetic. Especially when it could be made to be=
used with any string type (that provides a conversion to `string_view`) wi=
th ease.<br><br>If you want to suggest that `basic_string` and `string_view=
` should have member versions that call the non-member algorithms, fine. Bu=
t the non-member function is where the actual work happens.<br>=C2=A0</div>=
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><p>All of the=
m returns a 'vector' and I think is the main waited=20
result.</p></div></blockquote><div><br>No.<br><br>While we should not be ig=
norant of what other languages are doing, we also should not pretend that t=
he design of other languages is a priori correct for C++. We should do what=
is best for C++.<br><br>And one principle of C++ is that we do not make pe=
ople pay for features they don't need to use. Forcing the return of a `=
vector` makes people pay for memory allocations that they may not use.<br><=
br></div><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"><p>I=
think it should=20
not be required to mastering all subtilities of the STL to do something a s=
imple=20
as that.</p></div></blockquote><div><br>Master the subtleties of what? Of u=
sing a range? That should be an early lesson for C++ programmers; it's =
hardly deep metaprogramming magic.<br><br>If you're going to be able to=
work in a language, you <i>need</i> to know its idioms. And ranges are ver=
y important idioms in C++. We shouldn't cater to the demographic of peo=
ple who learn just the syntax of a language and then pretend that they know=
it.<br><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
ltr">
<p>I think it should be possible to write :</p>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#008">auto</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">MyResult</span><span style=3D"color:#660">=3D</span><=
span style=3D"color:#000"> </span><span style=3D"color:#080">"my,csv,l=
ine"</span><span style=3D"color:#000">s</span><span style=3D"color:#66=
0">.</span><span style=3D"color:#000">split</span><span style=3D"color:#660=
">(</span><span style=3D"color:#080">","</span><span style=3D"col=
or:#660">);</span><span style=3D"color:#000"><br>myvar</span><span style=3D=
"color:#660">=3D</span><span style=3D"color:#606">MyResult</span><span styl=
e=3D"color:#660">[</span><span style=3D"color:#066">1</span><span style=3D"=
color:#660">];</span><span style=3D"color:#000"> <br></span><span style=3D"=
color:#008">for</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#008">auto</span><span style=3D"color:#000"> sv </span><span style=3D"co=
lor:#660">:</span><span style=3D"color:#000"> </span><span style=3D"color:#=
606">MyResult</span><span style=3D"color:#660">)</span><span style=3D"color=
:#000"> <br></span></div></code></div><p></p></div></blockquote><div><br>He=
re is what that code would look like under the guidelines I (and others) ou=
tlined previously:<br><br><div style=3D"background-color: rgb(250, 250, 250=
); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px=
; overflow-wrap: break-word;" class=3D"prettyprint"><code class=3D"prettypr=
int"><div class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">vector </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">MyResult</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">split</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #080;" class=3D"styled-by-prettify">"my,c=
sv,line"</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #080;" class=3D"styled-by-prettify">","</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">));</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>myvar </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">MyResult</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color: #066;" =
class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">];</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">for</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> sv </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
606;" class=3D"styled-by-prettify">MyResult</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">)</span></div></code></div><br>See how sim=
ple that is? This only allocates memory in `vector`'s constructor (so y=
ou're not needlessly allocating a `basic_string`, just for a string lit=
eral).<br><br>Plus, if you just want the iteration, without the need for ra=
ndom access:<br><br><div style=3D"background-color: rgb(250, 250, 250); bor=
der-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; over=
flow-wrap: break-word;" class=3D"prettyprint"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">for</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> sv </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> split</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #080;" class=3D"styled-by-prettify">"my,csv,line"</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #08=
0;" class=3D"styled-by-prettify">","</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">))</span></div></code></div><br>This pe=
rforms <i>zero</i> memory allocations. Why <i>shouldn't</i> this be the=
default? In C++, the default ought to be fast, where possible.<br><br></di=
v><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;b=
order-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">
<p></p><p>Perhaps having multiple (like for stoi,l,ll) could be an option</=
p></div></blockquote><div><br>No. A single function returning a range, as o=
utlined above, can cover all of these cases effectively.<br></div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/172d08f0-a3da-4b9e-bfdd-985fb1f527c8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/172d08f0-a3da-4b9e-bfdd-985fb1f527c8=
%40isocpp.org</a>.<br />
------=_Part_688_969289153.1482680504224--
------=_Part_687_533956310.1482680504223--
.
Author: "dgutson ." <danielgutson@gmail.com>
Date: Sun, 25 Dec 2016 13:17:36 -0300
Raw View
--94eb2c05f4da1c1eec05447df558
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
El 25/12/2016 12:41, "Nicol Bolas" <jmckesson@gmail.com> escribi=C3=B3:
On Sunday, December 25, 2016 at 5:32:44 AM UTC-5, lnal...@gmail.com wrote:
>
> Hello,
>
>
> Most of modern language (D, Python, Java, C#, Go, Rust) got a split metho=
d
> on their string type, so I think it really make sense to have something
> similar in C++.
>
All of those languages also only have a single string type. C++ has
*hundreds*. Even the *standard library* has 2, and that doens't even count
`const char*`.
Having a `split` function that can *only* be used with the standard library
string types is pathetic. Especially when it could be made to be used with
any string type (that provides a conversion to `string_view`) with ease.
If you want to suggest that `basic_string` and `string_view` should have
member versions that call the non-member algorithms, fine. But the
non-member function is where the actual work happens.
> All of them returns a 'vector' and I think is the main waited result.
>
No.
While we should not be ignorant of what other languages are doing, we also
should not pretend that the design of other languages is a priori correct
for C++. We should do what is best for C++.
And one principle of C++ is that we do not make people pay for features
they don't need to use. Forcing the return of a `vector` makes people pay
for memory allocations that they may not use.
I think it should not be required to mastering all subtilities of the STL
> to do something a simple as that.
>
Master the subtleties of what? Of using a range? That should be an early
lesson for C++ programmers; it's hardly deep metaprogramming magic.
If you're going to be able to work in a language, you *need* to know its
idioms. And ranges are very important idioms in C++. We shouldn't cater to
the demographic of people who learn just the syntax of a language and then
pretend that they know it.
I think it should be possible to write :
> auto MyResult=3D "my,csv,line"s.split(",");
> myvar=3DMyResult[1];
> for(auto sv : MyResult)
>
>
Here is what that code would look like under the guidelines I (and others)
outlined previously:
vector MyResult(split("my,csv,line", ","));
myvar =3D MyResult[1];
for(auto sv : MyResult)
See how simple that is? This only allocates memory in `vector`'s
constructor (so you're not needlessly allocating a `basic_string`, just for
a string literal).
Plus, if you just want the iteration, without the need for random access:
for(auto sv : split("my,csv,line", ","))
This performs *zero* memory allocations. Why *shouldn't* this be the
default? In C++, the default ought to be fast, where possible.
I think there should also be a callback-oriented version by providing a
callable template argument (e.g. lambda, std::function, function ptr, etc)
which requires no memory allocation.
Perhaps having multiple (like for stoi,l,ll) could be an option
>
No. A single function returning a range, as outlined above, can cover all
of these cases effectively.
--=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
email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/
isocpp.org/d/msgid/std-proposals/172d08f0-a3da-4b9e-
bfdd-985fb1f527c8%40isocpp.org
<https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/172d08f0-a3da=
-4b9e-bfdd-985fb1f527c8%40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter=
>
..
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAFdMc-07FWpV07b3WSz0U%3DuDNHXM19xgBTH%3DCpt%3DK=
vty4886FQ%40mail.gmail.com.
--94eb2c05f4da1c1eec05447df558
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"auto"><div><br><div class=3D"gmail_extra"><br><div class=3D"gma=
il_quote">El 25/12/2016 12:41, "Nicol Bolas" <<a href=3D"mailt=
o:jmckesson@gmail.com">jmckesson@gmail.com</a>> escribi=C3=B3:<br type=
=3D"attribution"><blockquote class=3D"quote" style=3D"margin:0 0 0 .8ex;bor=
der-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div class=3D"qu=
oted-text">On Sunday, December 25, 2016 at 5:32:44 AM UTC-5, <a href=3D"mai=
lto:lnal...@gmail.com" target=3D"_blank">lnal...@gmail.com</a> wrote:<block=
quote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><p>Hello,</p><p><br>Most=
of modern language (D, Python, Java, C#, Go, Rust) got a split=20
method on their string type, so I think it really make sense to have someth=
ing=20
similar in C++.<br></p></div></blockquote></div><div><br>All of those langu=
ages also only have a single string type. C++ has <i>hundreds</i>. Even the=
<i>standard library</i> has 2, and that doens't even count `const char=
*`.<br><br>Having a `split` function that can <i>only</i> be used with the =
standard library string types is pathetic. Especially when it could be made=
to be used with any string type (that provides a conversion to `string_vie=
w`) with ease.<br><br>If you want to suggest that `basic_string` and `strin=
g_view` should have member versions that call the non-member algorithms, fi=
ne. But the non-member function is where the actual work happens.<br>=C2=A0=
</div><div class=3D"quoted-text"><blockquote class=3D"gmail_quote" style=3D=
"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><d=
iv dir=3D"ltr"><p>All of them returns a 'vector' and I think is the=
main waited=20
result.</p></div></blockquote></div><div><br>No.<br><br>While we should not=
be ignorant of what other languages are doing, we also should not pretend =
that the design of other languages is a priori correct for C++. We should d=
o what is best for C++.<br><br>And one principle of C++ is that we do not m=
ake people pay for features they don't need to use. Forcing the return =
of a `vector` makes people pay for memory allocations that they may not use=
..<br><br></div><div class=3D"quoted-text"><blockquote class=3D"gmail_quote"=
style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-lef=
t:1ex"><div dir=3D"ltr"><p>I think it should=20
not be required to mastering all subtilities of the STL to do something a s=
imple=20
as that.</p></div></blockquote></div><div><br>Master the subtleties of what=
? Of using a range? That should be an early lesson for C++ programmers; it&=
#39;s hardly deep metaprogramming magic.<br><br>If you're going to be a=
ble to work in a language, you <i>need</i> to know its idioms. And ranges a=
re very important idioms in C++. We shouldn't cater to the demographic =
of people who learn just the syntax of a language and then pretend that the=
y know it.<br><br></div><div class=3D"quoted-text"><blockquote class=3D"gma=
il_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><div dir=3D"ltr">
<p>I think it should be possible to write :</p>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#008">auto</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">MyResult</span><span style=3D"color:#660">=3D</span><=
span style=3D"color:#000"> </span><span style=3D"color:#080">"my,csv,l=
ine"</span><span style=3D"color:#000">s</span><span style=3D"color:#66=
0">.</span><span style=3D"color:#000">split</span><span style=3D"color:#660=
">(</span><span style=3D"color:#080">","</span><span style=3D"col=
or:#660">);</span><span style=3D"color:#000"><br>myvar</span><span style=3D=
"color:#660">=3D</span><span style=3D"color:#606">MyResult</span><span styl=
e=3D"color:#660">[</span><span style=3D"color:#066">1</span><span style=3D"=
color:#660">];</span><span style=3D"color:#000"> <br></span><span style=3D"=
color:#008">for</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#008">auto</span><span style=3D"color:#000"> sv </span><span style=3D"co=
lor:#660">:</span><span style=3D"color:#000"> </span><span style=3D"color:#=
606">MyResult</span><span style=3D"color:#660">)</span><span style=3D"color=
:#000"> <br></span></div></code></div><p></p></div></blockquote></div><div>=
<br>Here is what that code would look like under the guidelines I (and othe=
rs) outlined previously:<br><br><div style=3D"background-color:rgb(250,250,=
250);border-color:rgb(187,187,187);border-style:solid;border-width:1px" cla=
ss=3D"m_6587239836056522751prettyprint"><code class=3D"m_658723983605652275=
1prettyprint"><div class=3D"m_6587239836056522751subprettyprint"><span styl=
e=3D"color:#000" class=3D"m_6587239836056522751styled-by-prettify">vector <=
/span><span style=3D"color:#606" class=3D"m_6587239836056522751styled-by-pr=
ettify">MyResult</span><span style=3D"color:#660" class=3D"m_65872398360565=
22751styled-by-prettify">(</span><span style=3D"color:#000" class=3D"m_6587=
239836056522751styled-by-prettify">split</span><span style=3D"color:#660" c=
lass=3D"m_6587239836056522751styled-by-prettify">(</span><span style=3D"col=
or:#080" class=3D"m_6587239836056522751styled-by-prettify">"my,csv,lin=
e"</span><span style=3D"color:#660" class=3D"m_6587239836056522751styl=
ed-by-prettify">,</span><span style=3D"color:#000" class=3D"m_6587239836056=
522751styled-by-prettify"> </span><span style=3D"color:#080" class=3D"m_658=
7239836056522751styled-by-prettify">","</span><span style=3D"colo=
r:#660" class=3D"m_6587239836056522751styled-by-prettify">));</span><span s=
tyle=3D"color:#000" class=3D"m_6587239836056522751styled-by-prettify"><br>m=
yvar </span><span style=3D"color:#660" class=3D"m_6587239836056522751styled=
-by-prettify">=3D</span><span style=3D"color:#000" class=3D"m_6587239836056=
522751styled-by-prettify"> </span><span style=3D"color:#606" class=3D"m_658=
7239836056522751styled-by-prettify">MyResult</span><span style=3D"color:#66=
0" class=3D"m_6587239836056522751styled-by-prettify">[</span><span style=3D=
"color:#066" class=3D"m_6587239836056522751styled-by-prettify">1</span><spa=
n style=3D"color:#660" class=3D"m_6587239836056522751styled-by-prettify">];=
</span><span style=3D"color:#000" class=3D"m_6587239836056522751styled-by-p=
rettify"><br></span><span style=3D"color:#008" class=3D"m_65872398360565227=
51styled-by-prettify">for</span><span style=3D"color:#660" class=3D"m_65872=
39836056522751styled-by-prettify">(</span><span style=3D"color:#008" class=
=3D"m_6587239836056522751styled-by-prettify">auto</span><span style=3D"colo=
r:#000" class=3D"m_6587239836056522751styled-by-prettify"> sv </span><span =
style=3D"color:#660" class=3D"m_6587239836056522751styled-by-prettify">:</s=
pan><span style=3D"color:#000" class=3D"m_6587239836056522751styled-by-pret=
tify"> </span><span style=3D"color:#606" class=3D"m_6587239836056522751styl=
ed-by-prettify">MyResult</span><span style=3D"color:#660" class=3D"m_658723=
9836056522751styled-by-prettify">)</span></div></code></div><br>See how sim=
ple that is? This only allocates memory in `vector`'s constructor (so y=
ou're not needlessly allocating a `basic_string`, just for a string lit=
eral).<br><br>Plus, if you just want the iteration, without the need for ra=
ndom access:<br><br><div style=3D"background-color:rgb(250,250,250);border-=
color:rgb(187,187,187);border-style:solid;border-width:1px" class=3D"m_6587=
239836056522751prettyprint"><code class=3D"m_6587239836056522751prettyprint=
"><div class=3D"m_6587239836056522751subprettyprint"><span style=3D"color:#=
008" class=3D"m_6587239836056522751styled-by-prettify">for</span><span styl=
e=3D"color:#660" class=3D"m_6587239836056522751styled-by-prettify">(</span>=
<span style=3D"color:#008" class=3D"m_6587239836056522751styled-by-prettify=
">auto</span><span style=3D"color:#000" class=3D"m_6587239836056522751style=
d-by-prettify"> sv </span><span style=3D"color:#660" class=3D"m_65872398360=
56522751styled-by-prettify">:</span><span style=3D"color:#000" class=3D"m_6=
587239836056522751styled-by-prettify"> split</span><span style=3D"color:#66=
0" class=3D"m_6587239836056522751styled-by-prettify">(</span><span style=3D=
"color:#080" class=3D"m_6587239836056522751styled-by-prettify">"my,csv=
,line"</span><span style=3D"color:#660" class=3D"m_6587239836056522751=
styled-by-prettify">,</span><span style=3D"color:#000" class=3D"m_658723983=
6056522751styled-by-prettify"> </span><span style=3D"color:#080" class=3D"m=
_6587239836056522751styled-by-prettify">","</span><span style=3D"=
color:#660" class=3D"m_6587239836056522751styled-by-prettify">))</span></di=
v></code></div><br>This performs <i>zero</i> memory allocations. Why <i>sho=
uldn't</i> this be the default? In C++, the default ought to be fast, w=
here possible.<br></div></div></blockquote></div></div></div><div dir=3D"au=
to"><br></div><div dir=3D"auto">I think there should also be a callback-ori=
ented version by providing a callable template argument (e.g. lambda, std::=
function, function ptr, etc) which requires no memory allocation.</div><div=
dir=3D"auto"><br></div><div dir=3D"auto"><br></div><div dir=3D"auto"><div =
class=3D"gmail_extra"><div class=3D"gmail_quote"><blockquote class=3D"quote=
" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><=
div dir=3D"ltr"><div><br></div><div class=3D"quoted-text"><blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr">
<p></p><p>Perhaps having multiple (like for stoi,l,ll) could be an option</=
p></div></blockquote></div><div><br>No. A single function returning a range=
, as outlined above, can cover all of these cases effectively.<br></div></d=
iv><div class=3D"quoted-text">
<p></p>
-- <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" target=3D"_=
blank">std-proposals+unsubscribe@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br></div>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/172d08f0-a3da-4b9e-bfdd-985fb1f527c8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/172d=
08f0-a3da-4b9e-<wbr>bfdd-985fb1f527c8%40isocpp.org</a><wbr>.<br>
</blockquote></div><br></div></div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAFdMc-07FWpV07b3WSz0U%3DuDNHXM19xgBT=
H%3DCpt%3DKvty4886FQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFdMc-07FW=
pV07b3WSz0U%3DuDNHXM19xgBTH%3DCpt%3DKvty4886FQ%40mail.gmail.com</a>.<br />
--94eb2c05f4da1c1eec05447df558--
.
Author: "dgutson ." <danielgutson@gmail.com>
Date: Sun, 25 Dec 2016 13:20:11 -0300
Raw View
--001a1143df2654b60305447dfe0a
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
El 25/12/2016 13:17, "dgutson ." <danielgutson@gmail.com> escribi=C3=B3:
El 25/12/2016 12:41, "Nicol Bolas" <jmckesson@gmail.com> escribi=C3=B3:
On Sunday, December 25, 2016 at 5:32:44 AM UTC-5, lnal...@gmail.com wrote:
>
> Hello,
>
>
> Most of modern language (D, Python, Java, C#, Go, Rust) got a split metho=
d
> on their string type, so I think it really make sense to have something
> similar in C++.
>
All of those languages also only have a single string type. C++ has
*hundreds*. Even the *standard library* has 2, and that doens't even count
`const char*`.
Having a `split` function that can *only* be used with the standard library
string types is pathetic. Especially when it could be made to be used with
any string type (that provides a conversion to `string_view`) with ease.
If you want to suggest that `basic_string` and `string_view` should have
member versions that call the non-member algorithms, fine. But the
non-member function is where the actual work happens.
> All of them returns a 'vector' and I think is the main waited result.
>
No.
While we should not be ignorant of what other languages are doing, we also
should not pretend that the design of other languages is a priori correct
for C++. We should do what is best for C++.
And one principle of C++ is that we do not make people pay for features
they don't need to use. Forcing the return of a `vector` makes people pay
for memory allocations that they may not use.
I think it should not be required to mastering all subtilities of the STL
> to do something a simple as that.
>
Master the subtleties of what? Of using a range? That should be an early
lesson for C++ programmers; it's hardly deep metaprogramming magic.
If you're going to be able to work in a language, you *need* to know its
idioms. And ranges are very important idioms in C++. We shouldn't cater to
the demographic of people who learn just the syntax of a language and then
pretend that they know it.
I think it should be possible to write :
> auto MyResult=3D "my,csv,line"s.split(",");
> myvar=3DMyResult[1];
> for(auto sv : MyResult)
>
>
Here is what that code would look like under the guidelines I (and others)
outlined previously:
vector MyResult(split("my,csv,line", ","));
myvar =3D MyResult[1];
for(auto sv : MyResult)
See how simple that is? This only allocates memory in `vector`'s
constructor (so you're not needlessly allocating a `basic_string`, just for
a string literal).
Plus, if you just want the iteration, without the need for random access:
for(auto sv : split("my,csv,line", ","))
This performs *zero* memory allocations. Why *shouldn't* this be the
default? In C++, the default ought to be fast, where possible.
I think there should also be a callback-oriented version by providing a
callable template argument (e.g. lambda, std::function, function ptr, etc)
which requires no memory allocation.
BTW, this should work with any container that provides allocators,
containing any type equal-comparable:
vector<int> v;
split(v, 1, [](int x){});
Perhaps having multiple (like for stoi,l,ll) could be an option
>
No. A single function returning a range, as outlined above, can cover all
of these cases effectively.
--=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
email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/is
ocpp.org/d/msgid/std-proposals/172d08f0-a3da-4b9e-bfdd-
985fb1f527c8%40isocpp.org
<https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/172d08f0-a3da=
-4b9e-bfdd-985fb1f527c8%40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter=
>
..
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAFdMc-1sKQUs_ziOQwEZsOTLRDLrhjVSzLK_Jku27-Xwksc=
Q%2Bg%40mail.gmail.com.
--001a1143df2654b60305447dfe0a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"auto"><div><br><div class=3D"gmail_extra"><br><div class=3D"gma=
il_quote">El 25/12/2016 13:17, "dgutson ." <<a href=3D"mailto:=
danielgutson@gmail.com">danielgutson@gmail.com</a>> escribi=C3=B3:<br ty=
pe=3D"attribution"><blockquote class=3D"quote" style=3D"margin:0 0 0 .8ex;b=
order-left:1px #ccc solid;padding-left:1ex"><div dir=3D"auto"><div class=3D=
"elided-text"><div><br><div class=3D"gmail_extra"><br><div class=3D"gmail_q=
uote">El 25/12/2016 12:41, "Nicol Bolas" <<a href=3D"mailto:jm=
ckesson@gmail.com" target=3D"_blank">jmckesson@gmail.com</a>> escribi=C3=
=B3:<br type=3D"attribution"><blockquote class=3D"m_4043976793822217728quot=
e" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">=
<div dir=3D"ltr"><div class=3D"m_4043976793822217728quoted-text">On Sunday,=
December 25, 2016 at 5:32:44 AM UTC-5, <a href=3D"mailto:lnal...@gmail.com=
" target=3D"_blank">lnal...@gmail.com</a> wrote:<blockquote class=3D"gmail_=
quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;paddi=
ng-left:1ex"><div dir=3D"ltr"><p>Hello,</p><p><br>Most of modern language (=
D, Python, Java, C#, Go, Rust) got a split=20
method on their string type, so I think it really make sense to have someth=
ing=20
similar in C++.<br></p></div></blockquote></div><div><br>All of those langu=
ages also only have a single string type. C++ has <i>hundreds</i>. Even the=
<i>standard library</i> has 2, and that doens't even count `const char=
*`.<br><br>Having a `split` function that can <i>only</i> be used with the =
standard library string types is pathetic. Especially when it could be made=
to be used with any string type (that provides a conversion to `string_vie=
w`) with ease.<br><br>If you want to suggest that `basic_string` and `strin=
g_view` should have member versions that call the non-member algorithms, fi=
ne. But the non-member function is where the actual work happens.<br>=C2=A0=
</div><div class=3D"m_4043976793822217728quoted-text"><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"><p>All of them returns a 'vector=
9; and I think is the main waited=20
result.</p></div></blockquote></div><div><br>No.<br><br>While we should not=
be ignorant of what other languages are doing, we also should not pretend =
that the design of other languages is a priori correct for C++. We should d=
o what is best for C++.<br><br>And one principle of C++ is that we do not m=
ake people pay for features they don't need to use. Forcing the return =
of a `vector` makes people pay for memory allocations that they may not use=
..<br><br></div><div class=3D"m_4043976793822217728quoted-text"><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"><p>I think it should=20
not be required to mastering all subtilities of the STL to do something a s=
imple=20
as that.</p></div></blockquote></div><div><br>Master the subtleties of what=
? Of using a range? That should be an early lesson for C++ programmers; it&=
#39;s hardly deep metaprogramming magic.<br><br>If you're going to be a=
ble to work in a language, you <i>need</i> to know its idioms. And ranges a=
re very important idioms in C++. We shouldn't cater to the demographic =
of people who learn just the syntax of a language and then pretend that the=
y know it.<br><br></div><div class=3D"m_4043976793822217728quoted-text"><bl=
ockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">
<p>I think it should be possible to write :</p>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#008">auto</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">MyResult</span><span style=3D"color:#660">=3D</span><=
span style=3D"color:#000"> </span><span style=3D"color:#080">"my,csv,l=
ine"</span><span style=3D"color:#000">s</span><span style=3D"color:#66=
0">.</span><span style=3D"color:#000">split</span><span style=3D"color:#660=
">(</span><span style=3D"color:#080">","</span><span style=3D"col=
or:#660">);</span><span style=3D"color:#000"><br>myvar</span><span style=3D=
"color:#660">=3D</span><span style=3D"color:#606">MyResult</span><span styl=
e=3D"color:#660">[</span><span style=3D"color:#066">1</span><span style=3D"=
color:#660">];</span><span style=3D"color:#000"> <br></span><span style=3D"=
color:#008">for</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#008">auto</span><span style=3D"color:#000"> sv </span><span style=3D"co=
lor:#660">:</span><span style=3D"color:#000"> </span><span style=3D"color:#=
606">MyResult</span><span style=3D"color:#660">)</span><span style=3D"color=
:#000"> <br></span></div></code></div><p></p></div></blockquote></div><div>=
<br>Here is what that code would look like under the guidelines I (and othe=
rs) outlined previously:<br><br><div style=3D"background-color:rgb(250,250,=
250);border-color:rgb(187,187,187);border-style:solid;border-width:1px" cla=
ss=3D"m_4043976793822217728m_6587239836056522751prettyprint"><code class=3D=
"m_4043976793822217728m_6587239836056522751prettyprint"><div class=3D"m_404=
3976793822217728m_6587239836056522751subprettyprint"><span style=3D"color:#=
000" class=3D"m_4043976793822217728m_6587239836056522751styled-by-prettify"=
>vector </span><span style=3D"color:#606" class=3D"m_4043976793822217728m_6=
587239836056522751styled-by-prettify">MyResult</span><span style=3D"color:#=
660" class=3D"m_4043976793822217728m_6587239836056522751styled-by-prettify"=
>(</span><span style=3D"color:#000" class=3D"m_4043976793822217728m_6587239=
836056522751styled-by-prettify">split</span><span style=3D"color:#660" clas=
s=3D"m_4043976793822217728m_6587239836056522751styled-by-prettify">(</span>=
<span style=3D"color:#080" class=3D"m_4043976793822217728m_6587239836056522=
751styled-by-prettify">"my,csv,line"</span><span style=3D"color:#=
660" class=3D"m_4043976793822217728m_6587239836056522751styled-by-prettify"=
>,</span><span style=3D"color:#000" class=3D"m_4043976793822217728m_6587239=
836056522751styled-by-prettify"> </span><span style=3D"color:#080" class=3D=
"m_4043976793822217728m_6587239836056522751styled-by-prettify">","=
;</span><span style=3D"color:#660" class=3D"m_4043976793822217728m_65872398=
36056522751styled-by-prettify">));</span><span style=3D"color:#000" class=
=3D"m_4043976793822217728m_6587239836056522751styled-by-prettify"><br>myvar=
</span><span style=3D"color:#660" class=3D"m_4043976793822217728m_65872398=
36056522751styled-by-prettify">=3D</span><span style=3D"color:#000" class=
=3D"m_4043976793822217728m_6587239836056522751styled-by-prettify"> </span><=
span style=3D"color:#606" class=3D"m_4043976793822217728m_65872398360565227=
51styled-by-prettify">MyResult</span><span style=3D"color:#660" class=3D"m_=
4043976793822217728m_6587239836056522751styled-by-prettify">[</span><span s=
tyle=3D"color:#066" class=3D"m_4043976793822217728m_6587239836056522751styl=
ed-by-prettify">1</span><span style=3D"color:#660" class=3D"m_4043976793822=
217728m_6587239836056522751styled-by-prettify">];</span><span style=3D"colo=
r:#000" class=3D"m_4043976793822217728m_6587239836056522751styled-by-pretti=
fy"><br></span><span style=3D"color:#008" class=3D"m_4043976793822217728m_6=
587239836056522751styled-by-prettify">for</span><span style=3D"color:#660" =
class=3D"m_4043976793822217728m_6587239836056522751styled-by-prettify">(</s=
pan><span style=3D"color:#008" class=3D"m_4043976793822217728m_658723983605=
6522751styled-by-prettify">auto</span><span style=3D"color:#000" class=3D"m=
_4043976793822217728m_6587239836056522751styled-by-prettify"> sv </span><sp=
an style=3D"color:#660" class=3D"m_4043976793822217728m_6587239836056522751=
styled-by-prettify">:</span><span style=3D"color:#000" class=3D"m_404397679=
3822217728m_6587239836056522751styled-by-prettify"> </span><span style=3D"c=
olor:#606" class=3D"m_4043976793822217728m_6587239836056522751styled-by-pre=
ttify">MyResult</span><span style=3D"color:#660" class=3D"m_404397679382221=
7728m_6587239836056522751styled-by-prettify">)</span></div></code></div><br=
>See how simple that is? This only allocates memory in `vector`'s const=
ructor (so you're not needlessly allocating a `basic_string`, just for =
a string literal).<br><br>Plus, if you just want the iteration, without the=
need for random access:<br><br><div style=3D"background-color:rgb(250,250,=
250);border-color:rgb(187,187,187);border-style:solid;border-width:1px" cla=
ss=3D"m_4043976793822217728m_6587239836056522751prettyprint"><code class=3D=
"m_4043976793822217728m_6587239836056522751prettyprint"><div class=3D"m_404=
3976793822217728m_6587239836056522751subprettyprint"><span style=3D"color:#=
008" class=3D"m_4043976793822217728m_6587239836056522751styled-by-prettify"=
>for</span><span style=3D"color:#660" class=3D"m_4043976793822217728m_65872=
39836056522751styled-by-prettify">(</span><span style=3D"color:#008" class=
=3D"m_4043976793822217728m_6587239836056522751styled-by-prettify">auto</spa=
n><span style=3D"color:#000" class=3D"m_4043976793822217728m_65872398360565=
22751styled-by-prettify"> sv </span><span style=3D"color:#660" class=3D"m_4=
043976793822217728m_6587239836056522751styled-by-prettify">:</span><span st=
yle=3D"color:#000" class=3D"m_4043976793822217728m_6587239836056522751style=
d-by-prettify"> split</span><span style=3D"color:#660" class=3D"m_404397679=
3822217728m_6587239836056522751styled-by-prettify">(</span><span style=3D"c=
olor:#080" class=3D"m_4043976793822217728m_6587239836056522751styled-by-pre=
ttify">"my,csv,line"</span><span style=3D"color:#660" class=3D"m_=
4043976793822217728m_6587239836056522751styled-by-prettify">,</span><span s=
tyle=3D"color:#000" class=3D"m_4043976793822217728m_6587239836056522751styl=
ed-by-prettify"> </span><span style=3D"color:#080" class=3D"m_4043976793822=
217728m_6587239836056522751styled-by-prettify">","</span><span st=
yle=3D"color:#660" class=3D"m_4043976793822217728m_6587239836056522751style=
d-by-prettify">))</span></div></code></div><br>This performs <i>zero</i> me=
mory allocations. Why <i>shouldn't</i> this be the default? In C++, the=
default ought to be fast, where possible.<br></div></div></blockquote></di=
v></div></div><div dir=3D"auto"><br></div></div><div dir=3D"auto">I think t=
here should also be a callback-oriented version by providing a callable tem=
plate argument (e.g. lambda, std::function, function ptr, etc) which requir=
es no memory allocation.</div></div></blockquote></div></div></div><div dir=
=3D"auto"><br></div><div dir=3D"auto"><br></div><div dir=3D"auto">BTW, this=
should work with any container that provides allocators, containing any ty=
pe equal-comparable:</div><div dir=3D"auto"><br></div><div dir=3D"auto">vec=
tor<int> v;</div><div dir=3D"auto">split(v, 1, [](int x){});</div><di=
v dir=3D"auto"><div class=3D"gmail_extra"><div class=3D"gmail_quote"><block=
quote class=3D"quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid=
;padding-left:1ex"><div dir=3D"auto"><div class=3D"quoted-text"><div dir=3D=
"auto"><br></div><div dir=3D"auto"><br></div><div dir=3D"auto"><div class=
=3D"gmail_extra"><div class=3D"gmail_quote"><blockquote class=3D"m_40439767=
93822217728quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pad=
ding-left:1ex"><div dir=3D"ltr"><div><br></div><div class=3D"m_404397679382=
2217728quoted-text"><blockquote class=3D"gmail_quote" style=3D"margin:0;mar=
gin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr=
">
<p></p><p>Perhaps having multiple (like for stoi,l,ll) could be an option</=
p></div></blockquote></div><div><br>No. A single function returning a range=
, as outlined above, can cover all of these cases effectively.<br></div></d=
iv><div class=3D"m_4043976793822217728quoted-text">
<p></p>
-- <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" target=3D"_=
blank">std-proposals+unsubscribe@isoc<wbr>pp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br></div>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/172d08f0-a3da-4b9e-bfdd-985fb1f527c8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/is<wbr>ocpp.org/d/msgid/std-proposals<wbr>/172d=
08f0-a3da-4b9e-bfdd-<wbr>985fb1f527c8%40isocpp.org</a>.<br>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAFdMc-1sKQUs_ziOQwEZsOTLRDLrhjVSzLK_=
Jku27-XwkscQ%2Bg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFdMc-1sKQUs_z=
iOQwEZsOTLRDLrhjVSzLK_Jku27-XwkscQ%2Bg%40mail.gmail.com</a>.<br />
--001a1143df2654b60305447dfe0a--
.
Author: "dgutson ." <danielgutson@gmail.com>
Date: Sun, 25 Dec 2016 13:20:48 -0300
Raw View
--94eb2c0b1dde88c4c605447e007e
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
s/allocators/iterators/
El 25/12/2016 13:20, "dgutson ." <danielgutson@gmail.com> escribi=C3=B3:
>
>
> El 25/12/2016 13:17, "dgutson ." <danielgutson@gmail.com> escribi=C3=B3:
>
>
>
> El 25/12/2016 12:41, "Nicol Bolas" <jmckesson@gmail.com> escribi=C3=B3:
>
> On Sunday, December 25, 2016 at 5:32:44 AM UTC-5, lnal...@gmail.com wrote=
:
>>
>> Hello,
>>
>>
>> Most of modern language (D, Python, Java, C#, Go, Rust) got a split
>> method on their string type, so I think it really make sense to have
>> something similar in C++.
>>
>
> All of those languages also only have a single string type. C++ has
> *hundreds*. Even the *standard library* has 2, and that doens't even
> count `const char*`.
>
> Having a `split` function that can *only* be used with the standard
> library string types is pathetic. Especially when it could be made to be
> used with any string type (that provides a conversion to `string_view`)
> with ease.
>
> If you want to suggest that `basic_string` and `string_view` should have
> member versions that call the non-member algorithms, fine. But the
> non-member function is where the actual work happens.
>
>
>> All of them returns a 'vector' and I think is the main waited result.
>>
>
> No.
>
> While we should not be ignorant of what other languages are doing, we als=
o
> should not pretend that the design of other languages is a priori correct
> for C++. We should do what is best for C++.
>
> And one principle of C++ is that we do not make people pay for features
> they don't need to use. Forcing the return of a `vector` makes people pay
> for memory allocations that they may not use.
>
> I think it should not be required to mastering all subtilities of the STL
>> to do something a simple as that.
>>
>
> Master the subtleties of what? Of using a range? That should be an early
> lesson for C++ programmers; it's hardly deep metaprogramming magic.
>
> If you're going to be able to work in a language, you *need* to know its
> idioms. And ranges are very important idioms in C++. We shouldn't cater t=
o
> the demographic of people who learn just the syntax of a language and the=
n
> pretend that they know it.
>
> I think it should be possible to write :
>> auto MyResult=3D "my,csv,line"s.split(",");
>> myvar=3DMyResult[1];
>> for(auto sv : MyResult)
>>
>>
> Here is what that code would look like under the guidelines I (and others=
)
> outlined previously:
>
> vector MyResult(split("my,csv,line", ","));
> myvar =3D MyResult[1];
> for(auto sv : MyResult)
>
> See how simple that is? This only allocates memory in `vector`'s
> constructor (so you're not needlessly allocating a `basic_string`, just f=
or
> a string literal).
>
> Plus, if you just want the iteration, without the need for random access:
>
> for(auto sv : split("my,csv,line", ","))
>
> This performs *zero* memory allocations. Why *shouldn't* this be the
> default? In C++, the default ought to be fast, where possible.
>
>
> I think there should also be a callback-oriented version by providing a
> callable template argument (e.g. lambda, std::function, function ptr, etc=
)
> which requires no memory allocation.
>
>
>
> BTW, this should work with any container that provides allocators,
> containing any type equal-comparable:
>
> vector<int> v;
> split(v, 1, [](int x){});
>
>
>
>
> Perhaps having multiple (like for stoi,l,ll) could be an option
>>
>
> No. A single function returning a range, as outlined above, can cover all
> of these cases effectively.
>
> --
> 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.
> To view this discussion on the web visit https://groups.google.com/a/is
> ocpp.org/d/msgid/std-proposals/172d08f0-a3da-4b9e-bfdd-985fb
> 1f527c8%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/172d08f0-a3=
da-4b9e-bfdd-985fb1f527c8%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>
>
>
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAFdMc-2Fgm3A2JjbERdCeFqDDFFTHhWFLPEr6Jw4uPp2dw1=
Pbg%40mail.gmail.com.
--94eb2c0b1dde88c4c605447e007e
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"auto">s/allocators/iterators/</div><div class=3D"gmail_extra"><=
br><div class=3D"gmail_quote">El 25/12/2016 13:20, "dgutson ." &l=
t;<a href=3D"mailto:danielgutson@gmail.com">danielgutson@gmail.com</a>> =
escribi=C3=B3:<br type=3D"attribution"><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div =
dir=3D"auto"><div><br><div class=3D"gmail_extra"><br><div class=3D"gmail_qu=
ote">El 25/12/2016 13:17, "dgutson ." <<a href=3D"mailto:danie=
lgutson@gmail.com" target=3D"_blank">danielgutson@gmail.com</a>> escribi=
=C3=B3:<br type=3D"attribution"><blockquote class=3D"m_8621554246912952581q=
uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e=
x"><div dir=3D"auto"><div class=3D"m_8621554246912952581elided-text"><div><=
br><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">El 25/12/2016 =
12:41, "Nicol Bolas" <<a href=3D"mailto:jmckesson@gmail.com" t=
arget=3D"_blank">jmckesson@gmail.com</a>> escribi=C3=B3:<br type=3D"attr=
ibution"><blockquote class=3D"m_8621554246912952581m_4043976793822217728quo=
te" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"=
><div dir=3D"ltr"><div class=3D"m_8621554246912952581m_4043976793822217728q=
uoted-text">On Sunday, December 25, 2016 at 5:32:44 AM UTC-5, <a href=3D"ma=
ilto:lnal...@gmail.com" target=3D"_blank">lnal...@gmail.com</a> wrote:<bloc=
kquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-lef=
t:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><p>Hello,</p><p><br>Mos=
t of modern language (D, Python, Java, C#, Go, Rust) got a split=20
method on their string type, so I think it really make sense to have someth=
ing=20
similar in C++.<br></p></div></blockquote></div><div><br>All of those langu=
ages also only have a single string type. C++ has <i>hundreds</i>. Even the=
<i>standard library</i> has 2, and that doens't even count `const char=
*`.<br><br>Having a `split` function that can <i>only</i> be used with the =
standard library string types is pathetic. Especially when it could be made=
to be used with any string type (that provides a conversion to `string_vie=
w`) with ease.<br><br>If you want to suggest that `basic_string` and `strin=
g_view` should have member versions that call the non-member algorithms, fi=
ne. But the non-member function is where the actual work happens.<br>=C2=A0=
</div><div class=3D"m_8621554246912952581m_4043976793822217728quoted-text">=
<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;borde=
r-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><p>All of them ret=
urns a 'vector' and I think is the main waited=20
result.</p></div></blockquote></div><div><br>No.<br><br>While we should not=
be ignorant of what other languages are doing, we also should not pretend =
that the design of other languages is a priori correct for C++. We should d=
o what is best for C++.<br><br>And one principle of C++ is that we do not m=
ake people pay for features they don't need to use. Forcing the return =
of a `vector` makes people pay for memory allocations that they may not use=
..<br><br></div><div class=3D"m_8621554246912952581m_4043976793822217728quot=
ed-text"><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"><p>I thin=
k it should=20
not be required to mastering all subtilities of the STL to do something a s=
imple=20
as that.</p></div></blockquote></div><div><br>Master the subtleties of what=
? Of using a range? That should be an early lesson for C++ programmers; it&=
#39;s hardly deep metaprogramming magic.<br><br>If you're going to be a=
ble to work in a language, you <i>need</i> to know its idioms. And ranges a=
re very important idioms in C++. We shouldn't cater to the demographic =
of people who learn just the syntax of a language and then pretend that the=
y know it.<br><br></div><div class=3D"m_8621554246912952581m_40439767938222=
17728quoted-text"><blockquote class=3D"gmail_quote" style=3D"margin:0;margi=
n-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">
<p>I think it should be possible to write :</p>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#008">auto</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">MyResult</span><span style=3D"color:#660">=3D</span><=
span style=3D"color:#000"> </span><span style=3D"color:#080">"my,csv,l=
ine"</span><span style=3D"color:#000">s</span><span style=3D"color:#66=
0">.</span><span style=3D"color:#000">split</span><span style=3D"color:#660=
">(</span><span style=3D"color:#080">","</span><span style=3D"col=
or:#660">);</span><span style=3D"color:#000"><br>myvar</span><span style=3D=
"color:#660">=3D</span><span style=3D"color:#606">MyResult</span><span styl=
e=3D"color:#660">[</span><span style=3D"color:#066">1</span><span style=3D"=
color:#660">];</span><span style=3D"color:#000"> <br></span><span style=3D"=
color:#008">for</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#008">auto</span><span style=3D"color:#000"> sv </span><span style=3D"co=
lor:#660">:</span><span style=3D"color:#000"> </span><span style=3D"color:#=
606">MyResult</span><span style=3D"color:#660">)</span><span style=3D"color=
:#000"> <br></span></div></code></div><p></p></div></blockquote></div><div>=
<br>Here is what that code would look like under the guidelines I (and othe=
rs) outlined previously:<br><br><div style=3D"background-color:rgb(250,250,=
250);border-color:rgb(187,187,187);border-style:solid;border-width:1px" cla=
ss=3D"m_8621554246912952581m_4043976793822217728m_6587239836056522751pretty=
print"><code class=3D"m_8621554246912952581m_4043976793822217728m_658723983=
6056522751prettyprint"><div class=3D"m_8621554246912952581m_404397679382221=
7728m_6587239836056522751subprettyprint"><span style=3D"color:#000" class=
=3D"m_8621554246912952581m_4043976793822217728m_6587239836056522751styled-b=
y-prettify">vector </span><span style=3D"color:#606" class=3D"m_86215542469=
12952581m_4043976793822217728m_6587239836056522751styled-by-prettify">MyRes=
ult</span><span style=3D"color:#660" class=3D"m_8621554246912952581m_404397=
6793822217728m_6587239836056522751styled-by-prettify">(</span><span style=
=3D"color:#000" class=3D"m_8621554246912952581m_4043976793822217728m_658723=
9836056522751styled-by-prettify">split</span><span style=3D"color:#660" cla=
ss=3D"m_8621554246912952581m_4043976793822217728m_6587239836056522751styled=
-by-prettify">(</span><span style=3D"color:#080" class=3D"m_862155424691295=
2581m_4043976793822217728m_6587239836056522751styled-by-prettify">"my,=
csv,line"</span><span style=3D"color:#660" class=3D"m_8621554246912952=
581m_4043976793822217728m_6587239836056522751styled-by-prettify">,</span><s=
pan style=3D"color:#000" class=3D"m_8621554246912952581m_404397679382221772=
8m_6587239836056522751styled-by-prettify"> </span><span style=3D"color:#080=
" class=3D"m_8621554246912952581m_4043976793822217728m_6587239836056522751s=
tyled-by-prettify">","</span><span style=3D"color:#660" class=3D"=
m_8621554246912952581m_4043976793822217728m_6587239836056522751styled-by-pr=
ettify">));</span><span style=3D"color:#000" class=3D"m_8621554246912952581=
m_4043976793822217728m_6587239836056522751styled-by-prettify"><br>myvar </s=
pan><span style=3D"color:#660" class=3D"m_8621554246912952581m_404397679382=
2217728m_6587239836056522751styled-by-prettify">=3D</span><span style=3D"co=
lor:#000" class=3D"m_8621554246912952581m_4043976793822217728m_658723983605=
6522751styled-by-prettify"> </span><span style=3D"color:#606" class=3D"m_86=
21554246912952581m_4043976793822217728m_6587239836056522751styled-by-pretti=
fy">MyResult</span><span style=3D"color:#660" class=3D"m_862155424691295258=
1m_4043976793822217728m_6587239836056522751styled-by-prettify">[</span><spa=
n style=3D"color:#066" class=3D"m_8621554246912952581m_4043976793822217728m=
_6587239836056522751styled-by-prettify">1</span><span style=3D"color:#660" =
class=3D"m_8621554246912952581m_4043976793822217728m_6587239836056522751sty=
led-by-prettify">];</span><span style=3D"color:#000" class=3D"m_86215542469=
12952581m_4043976793822217728m_6587239836056522751styled-by-prettify"><br><=
/span><span style=3D"color:#008" class=3D"m_8621554246912952581m_4043976793=
822217728m_6587239836056522751styled-by-prettify">for</span><span style=3D"=
color:#660" class=3D"m_8621554246912952581m_4043976793822217728m_6587239836=
056522751styled-by-prettify">(</span><span style=3D"color:#008" class=3D"m_=
8621554246912952581m_4043976793822217728m_6587239836056522751styled-by-pret=
tify">auto</span><span style=3D"color:#000" class=3D"m_8621554246912952581m=
_4043976793822217728m_6587239836056522751styled-by-prettify"> sv </span><sp=
an style=3D"color:#660" class=3D"m_8621554246912952581m_4043976793822217728=
m_6587239836056522751styled-by-prettify">:</span><span style=3D"color:#000"=
class=3D"m_8621554246912952581m_4043976793822217728m_6587239836056522751st=
yled-by-prettify"> </span><span style=3D"color:#606" class=3D"m_86215542469=
12952581m_4043976793822217728m_6587239836056522751styled-by-prettify">MyRes=
ult</span><span style=3D"color:#660" class=3D"m_8621554246912952581m_404397=
6793822217728m_6587239836056522751styled-by-prettify">)</span></div></code>=
</div><br>See how simple that is? This only allocates memory in `vector`=
9;s constructor (so you're not needlessly allocating a `basic_string`, =
just for a string literal).<br><br>Plus, if you just want the iteration, wi=
thout the need for random access:<br><br><div style=3D"background-color:rgb=
(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-width=
:1px" class=3D"m_8621554246912952581m_4043976793822217728m_6587239836056522=
751prettyprint"><code class=3D"m_8621554246912952581m_4043976793822217728m_=
6587239836056522751prettyprint"><div class=3D"m_8621554246912952581m_404397=
6793822217728m_6587239836056522751subprettyprint"><span style=3D"color:#008=
" class=3D"m_8621554246912952581m_4043976793822217728m_6587239836056522751s=
tyled-by-prettify">for</span><span style=3D"color:#660" class=3D"m_86215542=
46912952581m_4043976793822217728m_6587239836056522751styled-by-prettify">(<=
/span><span style=3D"color:#008" class=3D"m_8621554246912952581m_4043976793=
822217728m_6587239836056522751styled-by-prettify">auto</span><span style=3D=
"color:#000" class=3D"m_8621554246912952581m_4043976793822217728m_658723983=
6056522751styled-by-prettify"> sv </span><span style=3D"color:#660" class=
=3D"m_8621554246912952581m_4043976793822217728m_6587239836056522751styled-b=
y-prettify">:</span><span style=3D"color:#000" class=3D"m_86215542469129525=
81m_4043976793822217728m_6587239836056522751styled-by-prettify"> split</spa=
n><span style=3D"color:#660" class=3D"m_8621554246912952581m_40439767938222=
17728m_6587239836056522751styled-by-prettify">(</span><span style=3D"color:=
#080" class=3D"m_8621554246912952581m_4043976793822217728m_6587239836056522=
751styled-by-prettify">"my,csv,line"</span><span style=3D"color:#=
660" class=3D"m_8621554246912952581m_4043976793822217728m_65872398360565227=
51styled-by-prettify">,</span><span style=3D"color:#000" class=3D"m_8621554=
246912952581m_4043976793822217728m_6587239836056522751styled-by-prettify"> =
</span><span style=3D"color:#080" class=3D"m_8621554246912952581m_404397679=
3822217728m_6587239836056522751styled-by-prettify">","</span><spa=
n style=3D"color:#660" class=3D"m_8621554246912952581m_4043976793822217728m=
_6587239836056522751styled-by-prettify">))</span></div></code></div><br>Thi=
s performs <i>zero</i> memory allocations. Why <i>shouldn't</i> this be=
the default? In C++, the default ought to be fast, where possible.<br></di=
v></div></blockquote></div></div></div><div dir=3D"auto"><br></div></div><d=
iv dir=3D"auto">I think there should also be a callback-oriented version by=
providing a callable template argument (e.g. lambda, std::function, functi=
on ptr, etc) which requires no memory allocation.</div></div></blockquote><=
/div></div></div><div dir=3D"auto"><br></div><div dir=3D"auto"><br></div><d=
iv dir=3D"auto">BTW, this should work with any container that provides allo=
cators, containing any type equal-comparable:</div><div dir=3D"auto"><br></=
div><div dir=3D"auto">vector<int> v;</div><div dir=3D"auto">split(v, =
1, [](int x){});</div><div dir=3D"auto"><div class=3D"gmail_extra"><div cla=
ss=3D"gmail_quote"><blockquote class=3D"m_8621554246912952581quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"auto"><div class=3D"m_8621554246912952581quoted-text"><div dir=3D"auto"=
><br></div><div dir=3D"auto"><br></div><div dir=3D"auto"><div class=3D"gmai=
l_extra"><div class=3D"gmail_quote"><blockquote class=3D"m_8621554246912952=
581m_4043976793822217728quote" style=3D"margin:0 0 0 .8ex;border-left:1px #=
ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><br></div><div class=3D"m=
_8621554246912952581m_4043976793822217728quoted-text"><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">
<p></p><p>Perhaps having multiple (like for stoi,l,ll) could be an option</=
p></div></blockquote></div><div><br>No. A single function returning a range=
, as outlined above, can cover all of these cases effectively.<br></div></d=
iv><div class=3D"m_8621554246912952581m_4043976793822217728quoted-text">
<p></p>
-- <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" target=3D"_=
blank">std-proposals+unsubscribe@isoc<wbr>pp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br></div>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/172d08f0-a3da-4b9e-bfdd-985fb1f527c8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/is<wbr>ocpp.org/d/msgid/std-proposals<wbr>/172d=
08f0-a3da-4b9e-bfdd-985fb<wbr>1f527c8%40isocpp.org</a>.<br>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div></div>
</blockquote></div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAFdMc-2Fgm3A2JjbERdCeFqDDFFTHhWFLPEr=
6Jw4uPp2dw1Pbg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFdMc-2Fgm3A2Jjb=
ERdCeFqDDFFTHhWFLPEr6Jw4uPp2dw1Pbg%40mail.gmail.com</a>.<br />
--94eb2c0b1dde88c4c605447e007e--
.
Author: "dgutson ." <danielgutson@gmail.com>
Date: Sun, 25 Dec 2016 13:25:36 -0300
Raw View
--94eb2c0ba0feb5666d05447e11d0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Sorry for the spam, last email of my burst. I'm too drunk due to Christmas
celebrations.
My amendment below:
On Sun, Dec 25, 2016 at 1:20 PM, dgutson . <danielgutson@gmail.com> wrote:
> s/allocators/iterators/
>
> El 25/12/2016 13:20, "dgutson ." <danielgutson@gmail.com> escribi=C3=B3:
>
>>
>>
>> El 25/12/2016 13:17, "dgutson ." <danielgutson@gmail.com> escribi=C3=B3:
>>
>>
>>
>> El 25/12/2016 12:41, "Nicol Bolas" <jmckesson@gmail.com> escribi=C3=B3:
>>
>> On Sunday, December 25, 2016 at 5:32:44 AM UTC-5, lnal...@gmail.com
>> wrote:
>>>
>>> Hello,
>>>
>>>
>>> Most of modern language (D, Python, Java, C#, Go, Rust) got a split
>>> method on their string type, so I think it really make sense to have
>>> something similar in C++.
>>>
>>
>> All of those languages also only have a single string type. C++ has
>> *hundreds*. Even the *standard library* has 2, and that doens't even
>> count `const char*`.
>>
>> Having a `split` function that can *only* be used with the standard
>> library string types is pathetic. Especially when it could be made to be
>> used with any string type (that provides a conversion to `string_view`)
>> with ease.
>>
>> If you want to suggest that `basic_string` and `string_view` should have
>> member versions that call the non-member algorithms, fine. But the
>> non-member function is where the actual work happens.
>>
>>
>>> All of them returns a 'vector' and I think is the main waited result.
>>>
>>
>> No.
>>
>> While we should not be ignorant of what other languages are doing, we
>> also should not pretend that the design of other languages is a priori
>> correct for C++. We should do what is best for C++.
>>
>> And one principle of C++ is that we do not make people pay for features
>> they don't need to use. Forcing the return of a `vector` makes people pa=
y
>> for memory allocations that they may not use.
>>
>> I think it should not be required to mastering all subtilities of the ST=
L
>>> to do something a simple as that.
>>>
>>
>> Master the subtleties of what? Of using a range? That should be an early
>> lesson for C++ programmers; it's hardly deep metaprogramming magic.
>>
>> If you're going to be able to work in a language, you *need* to know its
>> idioms. And ranges are very important idioms in C++. We shouldn't cater =
to
>> the demographic of people who learn just the syntax of a language and th=
en
>> pretend that they know it.
>>
>> I think it should be possible to write :
>>> auto MyResult=3D "my,csv,line"s.split(",");
>>> myvar=3DMyResult[1];
>>> for(auto sv : MyResult)
>>>
>>>
>> Here is what that code would look like under the guidelines I (and
>> others) outlined previously:
>>
>> vector MyResult(split("my,csv,line", ","));
>> myvar =3D MyResult[1];
>> for(auto sv : MyResult)
>>
>> See how simple that is? This only allocates memory in `vector`'s
>> constructor (so you're not needlessly allocating a `basic_string`, just =
for
>> a string literal).
>>
>> Plus, if you just want the iteration, without the need for random access=
:
>>
>> for(auto sv : split("my,csv,line", ","))
>>
>> This performs *zero* memory allocations. Why *shouldn't* this be the
>> default? In C++, the default ought to be fast, where possible.
>>
>>
>> I think there should also be a callback-oriented version by providing a
>> callable template argument (e.g. lambda, std::function, function ptr, et=
c)
>> which requires no memory allocation.
>>
>>
>>
>> BTW, this should work with any container that provides allocators,
>> containing any type equal-comparable:
>>
>> vector<int> v;
>> split(v, 1, [](int x){});
>>
>
vector <int> v;
split(v, 1, [ ] (const vector<int>& subvector) { });
You got the idea, someone more sobre surely can write this better :)
>
>>
>>
>> Perhaps having multiple (like for stoi,l,ll) could be an option
>>>
>>
>> No. A single function returning a range, as outlined above, can cover al=
l
>> of these cases effectively.
>>
>> --
>> You received this message because you are subscribed to the Google Group=
s
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n
>> email to std-proposals+unsubscribe@isocpp.org.
>> To post to this group, send email to std-proposals@isocpp.org.
>> To view this discussion on the web visit https://groups.google.com/a/is
>> ocpp.org/d/msgid/std-proposals/172d08f0-a3da-4b9e-bfdd-985fb
>> 1f527c8%40isocpp.org
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/172d08f0-a=
3da-4b9e-bfdd-985fb1f527c8%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>>
>>
>>
--=20
Who=E2=80=99s got the sweetest disposition?
One guess, that=E2=80=99s who?
Who=E2=80=99d never, ever start an argument?
Who never shows a bit of temperament?
Who's never wrong but always right?
Who'd never dream of starting a fight?
Who get stuck with all the bad luck?
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAFdMc-3RaU%2BgW0EnBPtSDsLVcxxBXmzxgrtJn_FtdWcub=
xVJeg%40mail.gmail.com.
--94eb2c0ba0feb5666d05447e11d0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Sorry for the spam, last email of my burst. I'm t=
oo drunk due to Christmas celebrations.<br></div>My amendment below:<br><di=
v class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Sun, Dec 25, 2016=
at 1:20 PM, dgutson . <span dir=3D"ltr"><<a href=3D"mailto:danielgutson=
@gmail.com" target=3D"_blank">danielgutson@gmail.com</a>></span> wrote:<=
br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"auto">s/allocators/iterators/=
</div><div class=3D"HOEnZb"><div class=3D"h5"><div class=3D"gmail_extra"><b=
r><div class=3D"gmail_quote">El 25/12/2016 13:20, "dgutson ." <=
;<a href=3D"mailto:danielgutson@gmail.com" target=3D"_blank">danielgutson@g=
mail.com</a>> escribi=C3=B3:<br type=3D"attribution"><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><div dir=3D"auto"><div><br><div class=3D"gmail_extra"><br><di=
v class=3D"gmail_quote">El 25/12/2016 13:17, "dgutson ." <<a h=
ref=3D"mailto:danielgutson@gmail.com" target=3D"_blank">danielgutson@gmail.=
com</a>> escribi=C3=B3:<br type=3D"attribution"><blockquote class=3D"m_-=
7363212210675436364m_8621554246912952581quote" style=3D"margin:0 0 0 .8ex;b=
order-left:1px #ccc solid;padding-left:1ex"><div dir=3D"auto"><div class=3D=
"m_-7363212210675436364m_8621554246912952581elided-text"><div><br><div clas=
s=3D"gmail_extra"><br><div class=3D"gmail_quote">El 25/12/2016 12:41, "=
;Nicol Bolas" <<a href=3D"mailto:jmckesson@gmail.com" target=3D"_bl=
ank">jmckesson@gmail.com</a>> escribi=C3=B3:<br type=3D"attribution"><bl=
ockquote class=3D"m_-7363212210675436364m_8621554246912952581m_404397679382=
2217728quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding=
-left:1ex"><div dir=3D"ltr"><div class=3D"m_-7363212210675436364m_862155424=
6912952581m_4043976793822217728quoted-text">On Sunday, December 25, 2016 at=
5:32:44 AM UTC-5, <a href=3D"mailto:lnal...@gmail.com" target=3D"_blank">l=
nal...@gmail.com</a> wrote:<blockquote class=3D"gmail_quote" style=3D"margi=
n:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr"><p>Hello,</p><p><br>Most of modern language (D, Python, Java, C#, =
Go, Rust) got a split=20
method on their string type, so I think it really make sense to have someth=
ing=20
similar in C++.<br></p></div></blockquote></div><div><br>All of those langu=
ages also only have a single string type. C++ has <i>hundreds</i>. Even the=
<i>standard library</i> has 2, and that doens't even count `const char=
*`.<br><br>Having a `split` function that can <i>only</i> be used with the =
standard library string types is pathetic. Especially when it could be made=
to be used with any string type (that provides a conversion to `string_vie=
w`) with ease.<br><br>If you want to suggest that `basic_string` and `strin=
g_view` should have member versions that call the non-member algorithms, fi=
ne. But the non-member function is where the actual work happens.<br>=C2=A0=
</div><div class=3D"m_-7363212210675436364m_8621554246912952581m_4043976793=
822217728quoted-text"><blockquote class=3D"gmail_quote" style=3D"margin:0;m=
argin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"l=
tr"><p>All of them returns a 'vector' and I think is the main waite=
d=20
result.</p></div></blockquote></div><div><br>No.<br><br>While we should not=
be ignorant of what other languages are doing, we also should not pretend =
that the design of other languages is a priori correct for C++. We should d=
o what is best for C++.<br><br>And one principle of C++ is that we do not m=
ake people pay for features they don't need to use. Forcing the return =
of a `vector` makes people pay for memory allocations that they may not use=
..<br><br></div><div class=3D"m_-7363212210675436364m_8621554246912952581m_4=
043976793822217728quoted-text"><blockquote class=3D"gmail_quote" style=3D"m=
argin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div=
dir=3D"ltr"><p>I think it should=20
not be required to mastering all subtilities of the STL to do something a s=
imple=20
as that.</p></div></blockquote></div><div><br>Master the subtleties of what=
? Of using a range? That should be an early lesson for C++ programmers; it&=
#39;s hardly deep metaprogramming magic.<br><br>If you're going to be a=
ble to work in a language, you <i>need</i> to know its idioms. And ranges a=
re very important idioms in C++. We shouldn't cater to the demographic =
of people who learn just the syntax of a language and then pretend that the=
y know it.<br><br></div><div class=3D"m_-7363212210675436364m_8621554246912=
952581m_4043976793822217728quoted-text"><blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:=
1ex"><div dir=3D"ltr">
<p>I think it should be possible to write :</p>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#008">auto</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">MyResult</span><span style=3D"color:#660">=3D</span><=
span style=3D"color:#000"> </span><span style=3D"color:#080">"my,csv,l=
ine"</span><span style=3D"color:#000">s</span><span style=3D"color:#66=
0">.</span><span style=3D"color:#000">split</span><span style=3D"color:#660=
">(</span><span style=3D"color:#080">","</span><span style=3D"col=
or:#660">);</span><span style=3D"color:#000"><br>myvar</span><span style=3D=
"color:#660">=3D</span><span style=3D"color:#606">MyResult</span><span styl=
e=3D"color:#660">[</span><span style=3D"color:#066">1</span><span style=3D"=
color:#660">];</span><span style=3D"color:#000"> <br></span><span style=3D"=
color:#008">for</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#008">auto</span><span style=3D"color:#000"> sv </span><span style=3D"co=
lor:#660">:</span><span style=3D"color:#000"> </span><span style=3D"color:#=
606">MyResult</span><span style=3D"color:#660">)</span><span style=3D"color=
:#000"> <br></span></div></code></div><p></p></div></blockquote></div><div>=
<br>Here is what that code would look like under the guidelines I (and othe=
rs) outlined previously:<br><br><div style=3D"background-color:rgb(250,250,=
250);border-color:rgb(187,187,187);border-style:solid;border-width:1px" cla=
ss=3D"m_-7363212210675436364m_8621554246912952581m_4043976793822217728m_658=
7239836056522751prettyprint"><code class=3D"m_-7363212210675436364m_8621554=
246912952581m_4043976793822217728m_6587239836056522751prettyprint"><div cla=
ss=3D"m_-7363212210675436364m_8621554246912952581m_4043976793822217728m_658=
7239836056522751subprettyprint"><span style=3D"color:#000" class=3D"m_-7363=
212210675436364m_8621554246912952581m_4043976793822217728m_6587239836056522=
751styled-by-prettify">vector </span><span style=3D"color:#606" class=3D"m_=
-7363212210675436364m_8621554246912952581m_4043976793822217728m_65872398360=
56522751styled-by-prettify">MyResult</span><span style=3D"color:#660" class=
=3D"m_-7363212210675436364m_8621554246912952581m_4043976793822217728m_65872=
39836056522751styled-by-prettify">(</span><span style=3D"color:#000" class=
=3D"m_-7363212210675436364m_8621554246912952581m_4043976793822217728m_65872=
39836056522751styled-by-prettify">split</span><span style=3D"color:#660" cl=
ass=3D"m_-7363212210675436364m_8621554246912952581m_4043976793822217728m_65=
87239836056522751styled-by-prettify">(</span><span style=3D"color:#080" cla=
ss=3D"m_-7363212210675436364m_8621554246912952581m_4043976793822217728m_658=
7239836056522751styled-by-prettify">"my,csv,line"</span><span sty=
le=3D"color:#660" class=3D"m_-7363212210675436364m_8621554246912952581m_404=
3976793822217728m_6587239836056522751styled-by-prettify">,</span><span styl=
e=3D"color:#000" class=3D"m_-7363212210675436364m_8621554246912952581m_4043=
976793822217728m_6587239836056522751styled-by-prettify"> </span><span style=
=3D"color:#080" class=3D"m_-7363212210675436364m_8621554246912952581m_40439=
76793822217728m_6587239836056522751styled-by-prettify">","</span>=
<span style=3D"color:#660" class=3D"m_-7363212210675436364m_862155424691295=
2581m_4043976793822217728m_6587239836056522751styled-by-prettify">));</span=
><span style=3D"color:#000" class=3D"m_-7363212210675436364m_86215542469129=
52581m_4043976793822217728m_6587239836056522751styled-by-prettify"><br>myva=
r </span><span style=3D"color:#660" class=3D"m_-7363212210675436364m_862155=
4246912952581m_4043976793822217728m_6587239836056522751styled-by-prettify">=
=3D</span><span style=3D"color:#000" class=3D"m_-7363212210675436364m_86215=
54246912952581m_4043976793822217728m_6587239836056522751styled-by-prettify"=
> </span><span style=3D"color:#606" class=3D"m_-7363212210675436364m_862155=
4246912952581m_4043976793822217728m_6587239836056522751styled-by-prettify">=
MyResult</span><span style=3D"color:#660" class=3D"m_-7363212210675436364m_=
8621554246912952581m_4043976793822217728m_6587239836056522751styled-by-pret=
tify">[</span><span style=3D"color:#066" class=3D"m_-7363212210675436364m_8=
621554246912952581m_4043976793822217728m_6587239836056522751styled-by-prett=
ify">1</span><span style=3D"color:#660" class=3D"m_-7363212210675436364m_86=
21554246912952581m_4043976793822217728m_6587239836056522751styled-by-pretti=
fy">];</span><span style=3D"color:#000" class=3D"m_-7363212210675436364m_86=
21554246912952581m_4043976793822217728m_6587239836056522751styled-by-pretti=
fy"><br></span><span style=3D"color:#008" class=3D"m_-7363212210675436364m_=
8621554246912952581m_4043976793822217728m_6587239836056522751styled-by-pret=
tify">for</span><span style=3D"color:#660" class=3D"m_-7363212210675436364m=
_8621554246912952581m_4043976793822217728m_6587239836056522751styled-by-pre=
ttify">(</span><span style=3D"color:#008" class=3D"m_-7363212210675436364m_=
8621554246912952581m_4043976793822217728m_6587239836056522751styled-by-pret=
tify">auto</span><span style=3D"color:#000" class=3D"m_-7363212210675436364=
m_8621554246912952581m_4043976793822217728m_6587239836056522751styled-by-pr=
ettify"> sv </span><span style=3D"color:#660" class=3D"m_-73632122106754363=
64m_8621554246912952581m_4043976793822217728m_6587239836056522751styled-by-=
prettify">:</span><span style=3D"color:#000" class=3D"m_-736321221067543636=
4m_8621554246912952581m_4043976793822217728m_6587239836056522751styled-by-p=
rettify"> </span><span style=3D"color:#606" class=3D"m_-7363212210675436364=
m_8621554246912952581m_4043976793822217728m_6587239836056522751styled-by-pr=
ettify">MyResult</span><span style=3D"color:#660" class=3D"m_-7363212210675=
436364m_8621554246912952581m_4043976793822217728m_6587239836056522751styled=
-by-prettify">)</span></div></code></div><br>See how simple that is? This o=
nly allocates memory in `vector`'s constructor (so you're not needl=
essly allocating a `basic_string`, just for a string literal).<br><br>Plus,=
if you just want the iteration, without the need for random access:<br><br=
><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,1=
87);border-style:solid;border-width:1px" class=3D"m_-7363212210675436364m_8=
621554246912952581m_4043976793822217728m_6587239836056522751prettyprint"><c=
ode class=3D"m_-7363212210675436364m_8621554246912952581m_40439767938222177=
28m_6587239836056522751prettyprint"><div class=3D"m_-7363212210675436364m_8=
621554246912952581m_4043976793822217728m_6587239836056522751subprettyprint"=
><span style=3D"color:#008" class=3D"m_-7363212210675436364m_86215542469129=
52581m_4043976793822217728m_6587239836056522751styled-by-prettify">for</spa=
n><span style=3D"color:#660" class=3D"m_-7363212210675436364m_8621554246912=
952581m_4043976793822217728m_6587239836056522751styled-by-prettify">(</span=
><span style=3D"color:#008" class=3D"m_-7363212210675436364m_86215542469129=
52581m_4043976793822217728m_6587239836056522751styled-by-prettify">auto</sp=
an><span style=3D"color:#000" class=3D"m_-7363212210675436364m_862155424691=
2952581m_4043976793822217728m_6587239836056522751styled-by-prettify"> sv </=
span><span style=3D"color:#660" class=3D"m_-7363212210675436364m_8621554246=
912952581m_4043976793822217728m_6587239836056522751styled-by-prettify">:</s=
pan><span style=3D"color:#000" class=3D"m_-7363212210675436364m_86215542469=
12952581m_4043976793822217728m_6587239836056522751styled-by-prettify"> spli=
t</span><span style=3D"color:#660" class=3D"m_-7363212210675436364m_8621554=
246912952581m_4043976793822217728m_6587239836056522751styled-by-prettify">(=
</span><span style=3D"color:#080" class=3D"m_-7363212210675436364m_86215542=
46912952581m_4043976793822217728m_6587239836056522751styled-by-prettify">&q=
uot;my,csv,line"</span><span style=3D"color:#660" class=3D"m_-73632122=
10675436364m_8621554246912952581m_4043976793822217728m_6587239836056522751s=
tyled-by-prettify">,</span><span style=3D"color:#000" class=3D"m_-736321221=
0675436364m_8621554246912952581m_4043976793822217728m_6587239836056522751st=
yled-by-prettify"> </span><span style=3D"color:#080" class=3D"m_-7363212210=
675436364m_8621554246912952581m_4043976793822217728m_6587239836056522751sty=
led-by-prettify">","</span><span style=3D"color:#660" class=3D"m_=
-7363212210675436364m_8621554246912952581m_4043976793822217728m_65872398360=
56522751styled-by-prettify">))</span></div></code></div><br>This performs <=
i>zero</i> memory allocations. Why <i>shouldn't</i> this be the default=
? In C++, the default ought to be fast, where possible.<br></div></div></bl=
ockquote></div></div></div><div dir=3D"auto"><br></div></div><div dir=3D"au=
to">I think there should also be a callback-oriented version by providing a=
callable template argument (e.g. lambda, std::function, function ptr, etc)=
which requires no memory allocation.</div></div></blockquote></div></div><=
/div><div dir=3D"auto"><br></div><div dir=3D"auto"><br></div><div dir=3D"au=
to">BTW, this should work with any container that provides allocators, cont=
aining any type equal-comparable:</div><div dir=3D"auto"><br></div><div dir=
=3D"auto">vector<int> v;</div><div dir=3D"auto">split(v, 1, [](int x)=
{});</div></div></blockquote></div></div></div></div></blockquote><div><br>=
<br></div><div>vector <int> v;<br></div><div>split(v, 1, [ ] (const v=
ector<int>& subvector) { });<br><br></div><div>You got the idea, =
someone more sobre surely can write this better :)<br></div><div>=C2=A0</di=
v><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex"><div class=3D"HOEnZb"><div class=3D"h5"><d=
iv class=3D"gmail_extra"><div class=3D"gmail_quote"><blockquote class=3D"gm=
ail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-le=
ft:1ex"><div dir=3D"auto"><div dir=3D"auto"><div class=3D"gmail_extra"><div=
class=3D"gmail_quote"><blockquote class=3D"m_-7363212210675436364m_8621554=
246912952581quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><div dir=3D"auto"><div class=3D"m_-7363212210675436364m_862=
1554246912952581quoted-text"><div dir=3D"auto"><br></div><div dir=3D"auto">=
<br></div><div dir=3D"auto"><div class=3D"gmail_extra"><div class=3D"gmail_=
quote"><blockquote class=3D"m_-7363212210675436364m_8621554246912952581m_40=
43976793822217728quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc sol=
id;padding-left:1ex"><div dir=3D"ltr"><div><br></div><div class=3D"m_-73632=
12210675436364m_8621554246912952581m_4043976793822217728quoted-text"><block=
quote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">
<p></p><p>Perhaps having multiple (like for stoi,l,ll) could be an option</=
p></div></blockquote></div><div><br>No. A single function returning a range=
, as outlined above, can cover all of these cases effectively.<br></div></d=
iv><div class=3D"m_-7363212210675436364m_8621554246912952581m_4043976793822=
217728quoted-text">
<p></p>
-- <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" target=3D"_=
blank">std-proposals+unsubscribe@isoc<wbr>pp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br></div>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/172d08f0-a3da-4b9e-bfdd-985fb1f527c8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/is<wbr>ocpp.org/d/msgid/std-proposals<wbr>/172d=
08f0-a3da-4b9e-bfdd-985fb<wbr>1f527c8%40isocpp.org</a>.<br>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div></div></div>
</blockquote></div></div>
</div></div></blockquote></div><br><br clear=3D"all"><br>-- <br><div class=
=3D"gmail_signature" data-smartmail=3D"gmail_signature">Who=E2=80=99s got t=
he sweetest disposition?<br>One guess, that=E2=80=99s who?<br>Who=E2=80=99d=
never, ever start an argument?<br>Who never shows a bit of temperament?<br=
>Who's never wrong but always right?<br>Who'd never dream of starti=
ng a fight?<br>Who get stuck with all the bad luck? </div>
</div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAFdMc-3RaU%2BgW0EnBPtSDsLVcxxBXmzxgr=
tJn_FtdWcubxVJeg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFdMc-3RaU%2Bg=
W0EnBPtSDsLVcxxBXmzxgrtJn_FtdWcubxVJeg%40mail.gmail.com</a>.<br />
--94eb2c0ba0feb5666d05447e11d0--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 25 Dec 2016 09:27:47 -0800 (PST)
Raw View
------=_Part_644_1556758899.1482686867680
Content-Type: multipart/alternative;
boundary="----=_Part_645_1330595686.1482686867681"
------=_Part_645_1330595686.1482686867681
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Sunday, December 25, 2016 at 11:25:39 AM UTC-5, dgutson wrote:
>
> Sorry for the spam, last email of my burst. I'm too drunk due to Christma=
s=20
> celebrations.
> My amendment below:
>
> On Sun, Dec 25, 2016 at 1:20 PM, dgutson . <daniel...@gmail.com=20
> <javascript:>> wrote:
>
>> s/allocators/iterators/
>>
>> El 25/12/2016 13:20, "dgutson ." <daniel...@gmail.com <javascript:>>=20
>> escribi=C3=B3:
>>
>>>
>>>
>>> El 25/12/2016 13:17, "dgutson ." <daniel...@gmail.com <javascript:>>=20
>>> escribi=C3=B3:
>>>
>>>
>>>
>>> El 25/12/2016 12:41, "Nicol Bolas" <jmck...@gmail.com <javascript:>>=20
>>> escribi=C3=B3:
>>>
>>> On Sunday, December 25, 2016 at 5:32:44 AM UTC-5, lnal...@gmail.com=20
>>> wrote:
>>>>
>>>> Hello,
>>>>
>>>>
>>>> Most of modern language (D, Python, Java, C#, Go, Rust) got a split=20
>>>> method on their string type, so I think it really make sense to have=
=20
>>>> something similar in C++.
>>>>
>>>
>>> All of those languages also only have a single string type. C++ has=20
>>> *hundreds*. Even the *standard library* has 2, and that doens't even=20
>>> count `const char*`.
>>>
>>> Having a `split` function that can *only* be used with the standard=20
>>> library string types is pathetic. Especially when it could be made to b=
e=20
>>> used with any string type (that provides a conversion to `string_view`)=
=20
>>> with ease.
>>>
>>> If you want to suggest that `basic_string` and `string_view` should hav=
e=20
>>> member versions that call the non-member algorithms, fine. But the=20
>>> non-member function is where the actual work happens.
>>> =20
>>>
>>>> All of them returns a 'vector' and I think is the main waited result.
>>>>
>>>
>>> No.
>>>
>>> While we should not be ignorant of what other languages are doing, we=
=20
>>> also should not pretend that the design of other languages is a priori=
=20
>>> correct for C++. We should do what is best for C++.
>>>
>>> And one principle of C++ is that we do not make people pay for features=
=20
>>> they don't need to use. Forcing the return of a `vector` makes people p=
ay=20
>>> for memory allocations that they may not use.
>>>
>>> I think it should not be required to mastering all subtilities of the=
=20
>>>> STL to do something a simple as that.
>>>>
>>>
>>> Master the subtleties of what? Of using a range? That should be an earl=
y=20
>>> lesson for C++ programmers; it's hardly deep metaprogramming magic.
>>>
>>> If you're going to be able to work in a language, you *need* to know=20
>>> its idioms. And ranges are very important idioms in C++. We shouldn't c=
ater=20
>>> to the demographic of people who learn just the syntax of a language an=
d=20
>>> then pretend that they know it.
>>>
>>> I think it should be possible to write :
>>>> auto MyResult=3D "my,csv,line"s.split(",");
>>>> myvar=3DMyResult[1];=20
>>>> for(auto sv : MyResult)=20
>>>>
>>>>
>>> Here is what that code would look like under the guidelines I (and=20
>>> others) outlined previously:
>>>
>>> vector MyResult(split("my,csv,line", ","));
>>> myvar =3D MyResult[1];
>>> for(auto sv : MyResult)
>>>
>>> See how simple that is? This only allocates memory in `vector`'s=20
>>> constructor (so you're not needlessly allocating a `basic_string`, just=
for=20
>>> a string literal).
>>>
>>> Plus, if you just want the iteration, without the need for random acces=
s:
>>>
>>> for(auto sv : split("my,csv,line", ","))
>>>
>>> This performs *zero* memory allocations. Why *shouldn't* this be the=20
>>> default? In C++, the default ought to be fast, where possible.
>>>
>>>
>>> I think there should also be a callback-oriented version by providing a=
=20
>>> callable template argument (e.g. lambda, std::function, function ptr, e=
tc)=20
>>> which requires no memory allocation.
>>>
>>>
We don't need multiple versions. We can get the benefits of all of these=20
variants with just the range version. It's all about how you choose to=20
"store" the range. If you want no memory allocations, use `auto`. If you=20
want to allocate an array of `string_views`, use `vector<string_view>` or=
=20
just `vector`. If the string being split is temporary and you want to=20
allocate an array of actual strings, then use `vector<string>`.
If you want a callback to be called for each one, use for_each:
std::for_each(split(...), callback);
The performance characteristics of this should be more-or-less equivalent=
=20
to the performance characteristics of the callback-oriented version you=20
want.
We don't need a dozen different split functions; we can build all of the=20
rest manually and easily from just the lowest level one.
>>> BTW, this should work with any container that provides allocators,=20
>>> containing any type equal-comparable:
>>>
>>> vector<int> v;
>>> split(v, 1, [](int x){});
>>>
>>
>
> vector <int> v;
> split(v, 1, [ ] (const vector<int>& subvector) { });
>
> You got the idea, someone more sobre surely can write this better :)
>
The reason to limit `split` to strings specifically (and by "string", I=20
mean "contiguous range of characters") is because that restriction allows=
=20
us to use a specific concrete type for the resulting range's value_type:=20
`string_view`. Users are thus able to use a *specific* lingua franca type=
=20
that gives them reasonable safety and tools without making using the string=
=20
difficult. You can do things like equality test with literals and so forth,=
=20
which you can't do with an arbitrary iterator range type.
It also allows us to have the function take a `const char*` NUL-terminated=
=20
string. Plus, it allows us to implement that suggestion I made earlier,=20
where if you provide an rvalue for the input range to be split, then it=20
will move from that range into internal storage, so that it's much harder=
=20
to get pointers/references to temporaries. You wouldn't want to do that for=
=20
arbitrary containers of anything, but for strings, yes.
We should not over-generalize what we're making here. I'm sure there's some=
=20
need to split an arbitrary range into subranges based on an equality test=
=20
of a value. But that should be a different function from splitting a=20
string, based on quality-of-life for the resulting code.
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/2f450f27-18b4-440b-8f54-9fbc1e2598f9%40isocpp.or=
g.
------=_Part_645_1330595686.1482686867681
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Sunday, December 25, 2016 at 11:25:39 AM UTC-5,=
dgutson wrote:<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=
"><div>Sorry for the spam, last email of my burst. I'm too drunk due to=
Christmas celebrations.<br></div>My amendment below:<br><div><br><div clas=
s=3D"gmail_quote">On Sun, Dec 25, 2016 at 1:20 PM, dgutson . <span dir=3D"l=
tr"><<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
zYq31ja1CAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">daniel...@gmail.com</a>></span> wrote:<br><blockquote class=3D"gmail_=
quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1=
ex"><div dir=3D"auto">s/allocators/iterators/</div><div><div><div><br><div =
class=3D"gmail_quote">El 25/12/2016 13:20, "dgutson ." <<a hre=
f=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"zYq31ja1CAAJ" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';return tr=
ue;" onclick=3D"this.href=3D'javascript:';return true;">daniel...@g=
mail.com</a>> escribi=C3=B3:<br type=3D"attribution"><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><div dir=3D"auto"><div><br><div><br><div class=3D"gmail_quote=
">El 25/12/2016 13:17, "dgutson ." <<a href=3D"javascript:" ta=
rget=3D"_blank" gdf-obfuscated-mailto=3D"zYq31ja1CAAJ" rel=3D"nofollow" onm=
ousedown=3D"this.href=3D'javascript:';return true;" onclick=3D"this=
..href=3D'javascript:';return true;">daniel...@gmail.com</a>> esc=
ribi=C3=B3:<br type=3D"attribution"><blockquote style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"auto"><div><div><b=
r><div><br><div class=3D"gmail_quote">El 25/12/2016 12:41, "Nicol Bola=
s" <<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=
=3D"zYq31ja1CAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascri=
pt:';return true;" onclick=3D"this.href=3D'javascript:';return =
true;">jmck...@gmail.com</a>> escribi=C3=B3:<br type=3D"attribution"><bl=
ockquote style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left=
:1ex"><div dir=3D"ltr"><div>On Sunday, December 25, 2016 at 5:32:44 AM UTC-=
5, <a>lnal...@gmail.com</a> wrote:<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"><p>Hello,</p><p><br>Most of modern language (D, Python, J=
ava, C#, Go, Rust) got a split=20
method on their string type, so I think it really make sense to have someth=
ing=20
similar in C++.<br></p></div></blockquote></div><div><br>All of those langu=
ages also only have a single string type. C++ has <i>hundreds</i>. Even the=
<i>standard library</i> has 2, and that doens't even count `const char=
*`.<br><br>Having a `split` function that can <i>only</i> be used with the =
standard library string types is pathetic. Especially when it could be made=
to be used with any string type (that provides a conversion to `string_vie=
w`) with ease.<br><br>If you want to suggest that `basic_string` and `strin=
g_view` should have member versions that call the non-member algorithms, fi=
ne. But the non-member function is where the actual work happens.<br>=C2=A0=
</div><div><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"><p>All =
of them returns a 'vector' and I think is the main waited=20
result.</p></div></blockquote></div><div><br>No.<br><br>While we should not=
be ignorant of what other languages are doing, we also should not pretend =
that the design of other languages is a priori correct for C++. We should d=
o what is best for C++.<br><br>And one principle of C++ is that we do not m=
ake people pay for features they don't need to use. Forcing the return =
of a `vector` makes people pay for memory allocations that they may not use=
..<br><br></div><div><blockquote class=3D"gmail_quote" style=3D"margin:0;mar=
gin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr=
"><p>I think it should=20
not be required to mastering all subtilities of the STL to do something a s=
imple=20
as that.</p></div></blockquote></div><div><br>Master the subtleties of what=
? Of using a range? That should be an early lesson for C++ programmers; it&=
#39;s hardly deep metaprogramming magic.<br><br>If you're going to be a=
ble to work in a language, you <i>need</i> to know its idioms. And ranges a=
re very important idioms in C++. We shouldn't cater to the demographic =
of people who learn just the syntax of a language and then pretend that the=
y know it.<br><br></div><div><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div d=
ir=3D"ltr">
<p>I think it should be possible to write :</p>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#008">auto</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">MyResult</span><span style=3D"color:#660">=3D</span><=
span style=3D"color:#000"> </span><span style=3D"color:#080">"my,csv,l=
ine"</span><span style=3D"color:#000">s</span><span style=3D"color:#66=
0">.</span><span style=3D"color:#000">split</span><span style=3D"color:#660=
">(</span><span style=3D"color:#080">","</span><span style=3D"col=
or:#660">);</span><span style=3D"color:#000"><br>myvar</span><span style=3D=
"color:#660">=3D</span><span style=3D"color:#606">MyResult</span><span styl=
e=3D"color:#660">[</span><span style=3D"color:#066">1</span><span style=3D"=
color:#660">];</span><span style=3D"color:#000"> <br></span><span style=3D"=
color:#008">for</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#008">auto</span><span style=3D"color:#000"> sv </span><span style=3D"co=
lor:#660">:</span><span style=3D"color:#000"> </span><span style=3D"color:#=
606">MyResult</span><span style=3D"color:#660">)</span><span style=3D"color=
:#000"> <br></span></div></code></div><p></p></div></blockquote></div><div>=
<br>Here is what that code would look like under the guidelines I (and othe=
rs) outlined previously:<br><br><div style=3D"background-color:rgb(250,250,=
250);border-color:rgb(187,187,187);border-style:solid;border-width:1px"><co=
de><div><span style=3D"color:#000">vector </span><span style=3D"color:#606"=
>MyResult</span><span style=3D"color:#660">(</span><span style=3D"color:#00=
0">split</span><span style=3D"color:#660">(</span><span style=3D"color:#080=
">"my,csv,line"</span><span style=3D"color:#660">,</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#080">","</span><=
span style=3D"color:#660">));</span><span style=3D"color:#000"><br>myvar </=
span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#606">MyResult</span><span style=3D"color:#660">[</s=
pan><span style=3D"color:#066">1</span><span style=3D"color:#660">];</span>=
<span style=3D"color:#000"><br></span><span style=3D"color:#008">for</span>=
<span style=3D"color:#660">(</span><span style=3D"color:#008">auto</span><s=
pan style=3D"color:#000"> sv </span><span style=3D"color:#660">:</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#606">MyResult</span><s=
pan style=3D"color:#660">)</span></div></code></div><br>See how simple that=
is? This only allocates memory in `vector`'s constructor (so you'r=
e not needlessly allocating a `basic_string`, just for a string literal).<b=
r><br>Plus, if you just want the iteration, without the need for random acc=
ess:<br><br><div style=3D"background-color:rgb(250,250,250);border-color:rg=
b(187,187,187);border-style:solid;border-width:1px"><code><div><span style=
=3D"color:#008">for</span><span style=3D"color:#660">(</span><span style=3D=
"color:#008">auto</span><span style=3D"color:#000"> sv </span><span style=
=3D"color:#660">:</span><span style=3D"color:#000"> split</span><span style=
=3D"color:#660">(</span><span style=3D"color:#080">"my,csv,line"<=
/span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span=
><span style=3D"color:#080">","</span><span style=3D"color:#660">=
))</span></div></code></div><br>This performs <i>zero</i> memory allocation=
s. Why <i>shouldn't</i> this be the default? In C++, the default ought =
to be fast, where possible.<br></div></div></blockquote></div></div></div><=
div dir=3D"auto"><br></div></div><div dir=3D"auto">I think there should als=
o be a callback-oriented version by providing a callable template argument =
(e.g. lambda, std::function, function ptr, etc) which requires no memory al=
location.</div></div></blockquote></div></div></div></div></blockquote></di=
v></div></div></div></blockquote></div></div></div></blockquote><div><br>We=
don't need multiple versions. We can get the benefits of all of these =
variants with just the range version. It's all about how you choose to =
"store" the range. If you want no memory allocations, use `auto`.=
If you want to allocate an array of `string_views`, use `vector<string_=
view>` or just `vector`. If the string being split is temporary and you =
want to allocate an array of actual strings, then use `vector<string>=
`.<br><br>If you want a callback to be called for each one, use for_each:<b=
r><br><div style=3D"background-color: rgb(250, 250, 250); border-color: rgb=
(187, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: bre=
ak-word;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"s=
ubprettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify">st=
d</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">for_each</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">split</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(...),</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> callback</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">);</span></div></code></div><br>The pe=
rformance characteristics of this should be more-or-less equivalent to the =
performance characteristics of the callback-oriented version you want.<br><=
br>We don't need a dozen different split functions; we can build all of=
the rest manually and easily from just the lowest level one.<br><br></div>=
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div cla=
ss=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 =
..8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div><div class=
=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8=
ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"auto"><div dir=
=3D"auto"></div><div dir=3D"auto"><br></div><div dir=3D"auto">BTW, this sho=
uld work with any container that provides allocators, containing any type e=
qual-comparable:</div><div dir=3D"auto"><br></div><div dir=3D"auto">vector&=
lt;int> v;</div><div dir=3D"auto">split(v, 1, [](int x){});</div></div><=
/blockquote></div></div></div></div></blockquote><div><br><br></div><div>ve=
ctor <int> v;<br></div><div>split(v, 1, [ ] (const vector<int>&=
amp; subvector) { });<br><br></div><div>You got the idea, someone more sobr=
e surely can write this better :)<br></div></div></div></div></blockquote><=
div><br>The reason to limit `split` to strings specifically (and by "s=
tring", I mean "contiguous range of characters") is because =
that restriction allows us to use a specific concrete type for the resultin=
g range's value_type: `string_view`. Users are thus able to use a <i>sp=
ecific</i> lingua franca type that gives them reasonable safety and tools w=
ithout making using the string difficult. You can do things like equality t=
est with literals and so forth, which you can't do with an arbitrary it=
erator range type.<br><br>It also allows us to have the function take a `co=
nst char*` NUL-terminated string. Plus, it allows us to implement that sugg=
estion I made earlier, where if you provide an rvalue for the input range t=
o be split, then it will move from that range into internal storage, so tha=
t it's much harder to get pointers/references to temporaries. You would=
n't want to do that for arbitrary containers of anything, but for strin=
gs, yes.<br><br>We should not over-generalize what we're making here. I=
'm sure there's some need to split an arbitrary range into subrange=
s based on an equality test of a value. But that should be a different func=
tion from splitting a string, based on quality-of-life for the resulting co=
de.<br></div></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/2f450f27-18b4-440b-8f54-9fbc1e2598f9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/2f450f27-18b4-440b-8f54-9fbc1e2598f9=
%40isocpp.org</a>.<br />
------=_Part_645_1330595686.1482686867681--
------=_Part_644_1556758899.1482686867680--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sun, 25 Dec 2016 19:34:07 +0200
Raw View
On 25 December 2016 at 19:27, Nicol Bolas <jmckesson@gmail.com> wrote:
> We should not over-generalize what we're making here. I'm sure there's some
> need to split an arbitrary range into subranges based on an equality test of
> a value. But that should be a different function from splitting a string,
> based on quality-of-life for the resulting code.
+1,
we already have the over-general version, it's called std::mismatch.
Don't reinvent it, provide
a split that is easy to use, and don't strive for an over-general one
as we already have it.
--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFk2RUZvBrYRz%2BWVVrYOYh18Jr3PGsBEi2bnySi0-1fKWwtfEw%40mail.gmail.com.
.
Author: FrankHB1989 <frankhb1989@gmail.com>
Date: Sun, 25 Dec 2016 21:46:14 -0800 (PST)
Raw View
------=_Part_3785_1281925735.1482731174830
Content-Type: multipart/alternative;
boundary="----=_Part_3786_2039580158.1482731174830"
------=_Part_3786_2039580158.1482731174830
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
=E5=9C=A8 2016=E5=B9=B412=E6=9C=8825=E6=97=A5=E6=98=9F=E6=9C=9F=E6=97=A5 UT=
C+8=E4=B8=8B=E5=8D=8811:41:44=EF=BC=8CNicol Bolas=E5=86=99=E9=81=93=EF=BC=
=9A
>
>
> If you want to suggest that `basic_string` and `string_view` should have=
=20
> member versions that call the non-member algorithms, fine. But the=20
> non-member function is where the actual work happens.
>
Technically that's not true since we have as-if rules. There are other=20
differences like small string optimization (and they may have other side=20
effects not mentioned here) to necessity the distinction remained in=20
library API. However, despite these differences, it is still the necessary=
=20
evil for current implementations in reality, as compromise of difficulties=
=20
about relying solely on as-if rules (or with a few more like merging=20
allocation since C++14).=20
> =20
>
>> All of them returns a 'vector' and I think is the main waited result.
>>
>
> No.
>
> Quite opposite, that's actually often true. Most time we only needs the=
=20
result (as a value representing a "string", mathematically) but not=20
additional details of implementation of the sequence.=20
=20
> While we should not be ignorant of what other languages are doing, we als=
o=20
> should not pretend that the design of other languages is a priori correct=
=20
> for C++. We should do what is best for C++.
>
> And one principle of C++ is that we do not make people pay for features=
=20
> they don't need to use. Forcing the return of a `vector` makes people pay=
=20
> for memory allocations that they may not use.
>
> To force users keep the details they actually do not need polluting the=
=20
API is just against the zero overhead principle on abstraction. The current=
=20
language has almost no effect way to resolve it, if you still want zero=20
overhead on performance.
(Though I still think keep non-owning `string_view` vs. owning "value=20
types" distinct in public API is almost always good.)
=20
> I think it should not be required to mastering all subtilities of the STL=
=20
>> to do something a simple as that.
>>
>
> Master the subtleties of what? Of using a range? That should be an early=
=20
> lesson for C++ programmers; it's hardly deep metaprogramming magic.
>
> If you're going to be able to work in a language, you *need* to know its=
=20
> idioms. And ranges are very important idioms in C++. We shouldn't cater t=
o=20
> the demographic of people who learn just the syntax of a language and the=
n=20
> pretend that they know it.
>
> I think it should be possible to write :
>> auto MyResult=3D "my,csv,line"s.split(",");
>> myvar=3DMyResult[1];=20
>> for(auto sv : MyResult)=20
>>
>>
> Here is what that code would look like under the guidelines I (and others=
)=20
> outlined previously:
>
> vector MyResult(split("my,csv,line", ","));
> myvar =3D MyResult[1];
> for(auto sv : MyResult)
>
> See how simple that is? This only allocates memory in `vector`'s=20
> constructor (so you're not needlessly allocating a `basic_string`, just f=
or=20
> a string literal).
>
> Plus, if you just want the iteration, without the need for random access:
>
> for(auto sv : split("my,csv,line", ","))
>
> This performs *zero* memory allocations. Why *shouldn't* this be the=20
> default? In C++, the default ought to be fast, where possible.
>
> If simplicity is important... it should be reasonable fast, but not alway=
s=20
fastest. (Although this is almost the fastest here.) This solution is more=
=20
reasonable than using owning types like `basic_string` besides a bunch of=
=20
nominal typing issues (e.g. aliasing, type safety, etc), mostly is due to=
=20
avoiding difficulties to clarify the underlying resource consumption. The=
=20
evaluation should ideally be like constant expressions (still very hard to=
=20
implement currently) because such operation essentially needs no side=20
effect (in the sense of the language) at all. Making all additional=20
allocation eventually disappeared is a happy ending, but not a must in=20
sense of the original requirements, i.e. no-allocation *guarantee *should=
=20
be out of scope in the interface description of high-level operations not=
=20
being bound to memory management mechanism directly in general (similar to=
=20
you should not make `noexcept` everywhere); otherwise, you should at least=
=20
provide the space complexity requirement, but it sounds really strange to=
=20
make such description comes before the type requirements.
=20
> Perhaps having multiple (like for stoi,l,ll) could be an option
>>
>
> No. A single function returning a range, as outlined above, can cover all=
=20
> of these cases effectively.
>
--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/344024da-fdd8-478e-bd4e-3c47fa9e59ce%40isocpp.or=
g.
------=_Part_3786_2039580158.1482731174830
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>=E5=9C=A8 2016=E5=B9=B412=E6=9C=8825=E6=97=A5=E6=
=98=9F=E6=9C=9F=E6=97=A5 UTC+8=E4=B8=8B=E5=8D=8811:41:44=EF=BC=8CNicol Bola=
s=E5=86=99=E9=81=93=EF=BC=9A<blockquote class=3D"gmail_quote" style=3D"marg=
in: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><d=
iv dir=3D"ltr"><br><div>If you want to suggest that `basic_string` and `str=
ing_view` should have member versions that call the non-member algorithms, =
fine. But the non-member function is where the actual work happens.<br></di=
v></div></blockquote><div>Technically that's not true since we have as-=
if rules. There are other differences like small string optimization (and t=
hey may have other side effects not mentioned here) to necessity the distin=
ction remained in library API. However, despite these differences, it is st=
ill the necessary evil for current implementations in reality, as compromis=
e of difficulties about relying solely on as-if rules (or with a few more l=
ike merging allocation since C++14). <br></div><blockquote class=3D"gmail_q=
uote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pad=
ding-left: 1ex;"><div dir=3D"ltr"><div>=C2=A0</div><blockquote class=3D"gma=
il_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><div dir=3D"ltr"><p>All of them returns a 'vector' =
and I think is the main waited=20
result.</p></div></blockquote><div><br>No.<br><br></div></div></blockquote>=
<div>Quite opposite, that's actually often true. Most time we only need=
s the result (as a value representing a "string", mathematically)=
but not additional details of implementation of the sequence. <br>=C2=A0<b=
r></div><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"><div>=
While we should not be ignorant of what other languages are doing, we also =
should not pretend that the design of other languages is a priori correct f=
or C++. We should do what is best for C++.<br><br>And one principle of C++ =
is that we do not make people pay for features they don't need to use. =
Forcing the return of a `vector` makes people pay for memory allocations th=
at they may not use.<br><br></div></div></blockquote><div>To force users ke=
ep the details they actually do not need polluting the=20
API is just against the zero overhead principle on abstraction. The=20
current language has almost no effect way to resolve it, if you still=20
want zero overhead on performance.<br><br>(Though I still think keep non-ow=
ning
`string_view` vs. owning "value types" distinct in public API is=
almost
always good.)<br>=C2=A0<br></div><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"><div></div><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"><p>I think it should=20
not be required to mastering all subtilities of the STL to do something a s=
imple=20
as that.</p></div></blockquote><div><br>Master the subtleties of what? Of u=
sing a range? That should be an early lesson for C++ programmers; it's =
hardly deep metaprogramming magic.<br><br>If you're going to be able to=
work in a language, you <i>need</i> to know its idioms. And ranges are ver=
y important idioms in C++. We shouldn't cater to the demographic of peo=
ple who learn just the syntax of a language and then pretend that they know=
it.<br><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0;margi=
n-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">
<p>I think it should be possible to write :</p>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,18=
7);border-style:solid;border-width:1px;word-wrap:break-word"><code><div><sp=
an style=3D"color:#008">auto</span><span style=3D"color:#000"> </span><span=
style=3D"color:#606">MyResult</span><span style=3D"color:#660">=3D</span><=
span style=3D"color:#000"> </span><span style=3D"color:#080">"my,csv,l=
ine"</span><span style=3D"color:#000">s</span><span style=3D"color:#66=
0">.</span><span style=3D"color:#000">split</span><span style=3D"color:#660=
">(</span><span style=3D"color:#080">","</span><span style=3D"col=
or:#660">);</span><span style=3D"color:#000"><br>myvar</span><span style=3D=
"color:#660">=3D</span><span style=3D"color:#606">MyResult</span><span styl=
e=3D"color:#660">[</span><span style=3D"color:#066">1</span><span style=3D"=
color:#660">];</span><span style=3D"color:#000"> <br></span><span style=3D"=
color:#008">for</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#008">auto</span><span style=3D"color:#000"> sv </span><span style=3D"co=
lor:#660">:</span><span style=3D"color:#000"> </span><span style=3D"color:#=
606">MyResult</span><span style=3D"color:#660">)</span><span style=3D"color=
:#000"> <br></span></div></code></div><p></p></div></blockquote><div><br>He=
re is what that code would look like under the guidelines I (and others) ou=
tlined previously:<br><br><div style=3D"background-color:rgb(250,250,250);b=
order-color:rgb(187,187,187);border-style:solid;border-width:1px"><code><di=
v><span style=3D"color:#000">vector </span><span style=3D"color:#606">MyRes=
ult</span><span style=3D"color:#660">(</span><span style=3D"color:#000">spl=
it</span><span style=3D"color:#660">(</span><span style=3D"color:#080">&quo=
t;my,csv,line"</span><span style=3D"color:#660">,</span><span style=3D=
"color:#000"> </span><span style=3D"color:#080">","</span><span s=
tyle=3D"color:#660">));</span><span style=3D"color:#000"><br>myvar </span><=
span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#606">MyResult</span><span style=3D"color:#660">[</span><s=
pan style=3D"color:#066">1</span><span style=3D"color:#660">];</span><span =
style=3D"color:#000"><br></span><span style=3D"color:#008">for</span><span =
style=3D"color:#660">(</span><span style=3D"color:#008">auto</span><span st=
yle=3D"color:#000"> sv </span><span style=3D"color:#660">:</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#606">MyResult</span><span st=
yle=3D"color:#660">)</span></div></code></div><br>See how simple that is? T=
his only allocates memory in `vector`'s constructor (so you're not =
needlessly allocating a `basic_string`, just for a string literal).<br><br>=
Plus, if you just want the iteration, without the need for random access:<b=
r><br><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,=
187,187);border-style:solid;border-width:1px"><code><div><span style=3D"col=
or:#008">for</span><span style=3D"color:#660">(</span><span style=3D"color:=
#008">auto</span><span style=3D"color:#000"> sv </span><span style=3D"color=
:#660">:</span><span style=3D"color:#000"> split</span><span style=3D"color=
:#660">(</span><span style=3D"color:#080">"my,csv,line"</span><sp=
an style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#080">","</span><span style=3D"color:#660">))</span>=
</div></code></div><br>This performs <i>zero</i> memory allocations. Why <i=
>shouldn't</i> this be the default? In C++, the default ought to be fas=
t, where possible.<br><br></div></div></blockquote><div>If simplicity is im=
portant... it should be reasonable fast, but not always fastest. (Although =
this is almost the fastest here.) This solution is more reasonable than usi=
ng owning types like `basic_string` besides a bunch of nominal typing issue=
s (e.g. aliasing, type safety, etc), mostly is due to avoiding difficulties=
to clarify the underlying resource consumption. The evaluation should idea=
lly be like constant expressions (still very hard to implement currently) b=
ecause such operation essentially needs no side effect (in the sense of the=
language) at all. Making all additional allocation eventually disappeared =
is a happy ending, but not a must in sense of the original requirements, i.=
e. no-allocation <b>guarantee </b>should be out of scope in the interface d=
escription of high-level operations not being bound to memory management me=
chanism directly in general (similar to you should not make `noexcept` ever=
ywhere); otherwise, you should at least provide the space complexity requir=
ement, but it sounds really strange to make such description comes before t=
he type requirements.<br>=C2=A0<br></div><blockquote class=3D"gmail_quote" =
style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-l=
eft: 1ex;"><div dir=3D"ltr"><div></div><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1=
ex"><div dir=3D"ltr">
<p></p><p>Perhaps having multiple (like for stoi,l,ll) could be an option</=
p></div></blockquote><div><br>No. A single function returning a range, as o=
utlined above, can cover all of these cases effectively.<br></div></div></b=
lockquote></div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/344024da-fdd8-478e-bd4e-3c47fa9e59ce%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/344024da-fdd8-478e-bd4e-3c47fa9e59ce=
%40isocpp.org</a>.<br />
------=_Part_3786_2039580158.1482731174830--
------=_Part_3785_1281925735.1482731174830--
.
Author: FrankHB1989 <frankhb1989@gmail.com>
Date: Sun, 25 Dec 2016 22:22:16 -0800 (PST)
Raw View
------=_Part_18_743172975.1482733336182
Content-Type: multipart/alternative;
boundary="----=_Part_19_2084598420.1482733336182"
------=_Part_19_2084598420.1482733336182
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
=E5=9C=A8 2016=E5=B9=B412=E6=9C=8826=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=80 UT=
C+8=E4=B8=8A=E5=8D=881:27:47=EF=BC=8CNicol Bolas=E5=86=99=E9=81=93=EF=BC=9A
>
>
>
>
>
> We don't need multiple versions. We can get the benefits of all of these=
=20
> variants with just the range version. It's all about how you choose to=20
> "store" the range. If you want no memory allocations, use `auto`. If you=
=20
> want to allocate an array of `string_views`, use `vector<string_view>` or=
=20
> just `vector`. If the string being split is temporary and you want to=20
> allocate an array of actual strings, then use `vector<string>`.
>
> If you want a callback to be called for each one, use for_each:
>
> std::for_each(split(...), callback);
>
> The performance characteristics of this should be more-or-less equivalent=
=20
> to the performance characteristics of the callback-oriented version you=
=20
> want.
>
> That's not true. Suppose you need only to collect the positions to be=20
split (and to pass the result to client code elsewhere, for example), your=
=20
solution make almost a half bloat in the intermediate result (in the=20
`vector`), because the spans are consequence and almost a half of results=
=20
are redundant in such case. This may require (sadly) excessive memory=20
allocation which is hardly to be optimized away as far as I know, so it is=
=20
not "more-or-less equivalent".
=20
> We don't need a dozen different split functions; we can build all of the=
=20
> rest manually and easily from just the lowest level one.
>
>
True, but it is questionable that you have really suggested "the lowest=20
level one". Moreover, I'm afraid if there is "one", not "two" or something=
=20
else.
For example, I'm not sure how to make my overloads fewer:
https://github.com/FrankHB/YSLib/blob/master/YBase/include/ystdex/algorithm=
..hpp#L215
https://github.com/FrankHB/YSLib/blob/master/YBase/include/ystdex/algorithm=
..hpp#L235=20
https://github.com/FrankHB/YSLib/blob/master/YBase/include/ystdex/algorithm=
..hpp#L263
=20
>
>>>> BTW, this should work with any container that provides allocators,=20
>>>> containing any type equal-comparable:
>>>>
>>>> vector<int> v;
>>>> split(v, 1, [](int x){});
>>>>
>>>
>>
>> vector <int> v;
>> split(v, 1, [ ] (const vector<int>& subvector) { });
>>
>> You got the idea, someone more sobre surely can write this better :)
>>
>
> The reason to limit `split` to strings specifically (and by "string", I=
=20
> mean "contiguous range of characters") is because that restriction allows=
=20
> us to use a specific concrete type for the resulting range's value_type:=
=20
> `string_view`. Users are thus able to use a *specific* lingua franca type=
=20
> that gives them reasonable safety and tools without making using the stri=
ng=20
> difficult. You can do things like equality test with literals and so fort=
h,=20
> which you can't do with an arbitrary iterator range type.
>
> But I really have some rather complicated use cases for non-strings based=
=20
on the very same algorithms, like:
https://github.com/FrankHB/YSLib/blob/master/YFramework/source/NPL/NPLA1.cp=
p#L162
(Note the callback versions has already the flexibility to make the result=
=20
as a `string_view`.) I don't want to reinvent the wheels.
Does the "specific" one really provide more?
(And you can't be too specific, anyway. You should also have=20
`basic_string_view<wchar_t>`, etc.)
=20
> It also allows us to have the function take a `const char*` NUL-terminate=
d=20
> string. Plus, it allows us to implement that suggestion I made earlier,=
=20
> where if you provide an rvalue for the input range to be split, then it=
=20
> will move from that range into internal storage, so that it's much harder=
=20
> to get pointers/references to temporaries. You wouldn't want to do that f=
or=20
> arbitrary containers of anything, but for strings, yes.
>
> We should not over-generalize what we're making here. I'm sure there's=20
> some need to split an arbitrary range into subranges based on an equality=
=20
> test of a value. But that should be a different function from splitting a=
=20
> string, based on quality-of-life for the resulting code.
>
Is it appropriate to bound the verb `split` tightly with strings now?=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/ac2c4208-fb06-4b28-84a9-09c2acce1495%40isocpp.or=
g.
------=_Part_19_2084598420.1482733336182
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>=E5=9C=A8 2016=E5=B9=B412=E6=9C=8826=E6=97=A5=E6=
=98=9F=E6=9C=9F=E4=B8=80 UTC+8=E4=B8=8A=E5=8D=881:27:47=EF=BC=8CNicol Bolas=
=E5=86=99=E9=81=93=EF=BC=9A<blockquote class=3D"gmail_quote" style=3D"margi=
n: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><di=
v dir=3D"ltr"><br><br><br><div><br>We don't need multiple versions. We =
can get the benefits of all of these variants with just the range version. =
It's all about how you choose to "store" the range. If you wa=
nt no memory allocations, use `auto`. If you want to allocate an array of `=
string_views`, use `vector<string_view>` or just `vector`. If the str=
ing being split is temporary and you want to allocate an array of actual st=
rings, then use `vector<string>`.<br><br>If you want a callback to be=
called for each one, use for_each:<br><br><div style=3D"background-color:r=
gb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-wid=
th:1px"><code><div><span style=3D"color:#000">std</span><span style=3D"colo=
r:#660">::</span><span style=3D"color:#000">for_each</span><span style=3D"c=
olor:#660">(</span><span style=3D"color:#000">split</span><span style=3D"co=
lor:#660">(...),</span><span style=3D"color:#000"> callback</span><span sty=
le=3D"color:#660">);</span></div></code></div><br>The performance character=
istics of this should be more-or-less equivalent to the performance charact=
eristics of the callback-oriented version you want.<br><br></div></div></bl=
ockquote><div>That's not true. Suppose you need only to collect the pos=
itions to be split (and to pass the result to client code elsewhere, for ex=
ample), your solution make almost a half bloat in the intermediate result (=
in the `vector`), because the spans are consequence and almost a half of re=
sults are redundant in such case. This may require (sadly) excessive memory=
allocation which is hardly to be optimized away as far as I know, so it is=
not "more-or-less equivalent".<br>=C2=A0<br></div><blockquote cl=
ass=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px =
#ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>We don't need a do=
zen different split functions; we can build all of the rest manually and ea=
sily from just the lowest level one.<br><br></div></div></blockquote><div><=
br>True, but it is questionable that you have really suggested "the lo=
west=20
level one". Moreover, I'm afraid if there is "one", not =
"two" or=20
something else.<br><br>For example, I'm not sure how to make my overloa=
ds fewer:<br><br>https://github.com/FrankHB/YSLib/blob/master/YBase/include=
/ystdex/algorithm.hpp#L215<br>https://github.com/FrankHB/YSLib/blob/master/=
YBase/include/ystdex/algorithm.hpp#L235 <br>https://github.com/FrankHB/YSLi=
b/blob/master/YBase/include/ystdex/algorithm.hpp#L263<br>=C2=A0</div><block=
quote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-le=
ft: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div></div><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1=
px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_q=
uote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div><div><div><div class=3D"gmail_quo=
te"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-lef=
t:1px #ccc solid;padding-left:1ex"><div dir=3D"auto"><div dir=3D"auto"></di=
v><div dir=3D"auto"><br></div><div dir=3D"auto">BTW, this should work with =
any container that provides allocators, containing any type equal-comparabl=
e:</div><div dir=3D"auto"><br></div><div dir=3D"auto">vector<int> v;<=
/div><div dir=3D"auto">split(v, 1, [](int x){});</div></div></blockquote></=
div></div></div></div></blockquote><div><br><br></div><div>vector <int&g=
t; v;<br></div><div>split(v, 1, [ ] (const vector<int>& subvector=
) { });<br><br></div><div>You got the idea, someone more sobre surely can w=
rite this better :)<br></div></div></div></div></blockquote><div><br>The re=
ason to limit `split` to strings specifically (and by "string", I=
mean "contiguous range of characters") is because that restricti=
on allows us to use a specific concrete type for the resulting range's =
value_type: `string_view`. Users are thus able to use a <i>specific</i> lin=
gua franca type that gives them reasonable safety and tools without making =
using the string difficult. You can do things like equality test with liter=
als and so forth, which you can't do with an arbitrary iterator range t=
ype.<br><br></div></div></blockquote><div>But I really have some rather com=
plicated use cases for non-strings based on the very same algorithms, like:=
<br>https://github.com/FrankHB/YSLib/blob/master/YFramework/source/NPL/NPLA=
1.cpp#L162<br><br>(Note the callback versions has already the flexibility t=
o make the result as a `string_view`.) I don't want to reinvent the whe=
els.<br><br>Does the "specific" one really provide more?<br><br>(=
And you can't be too specific, anyway. You should also have `basic_stri=
ng_view<wchar_t>`, etc.)<br>=C2=A0</div><blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padd=
ing-left: 1ex;"><div dir=3D"ltr"><div>It also allows us to have the functio=
n take a `const char*` NUL-terminated string. Plus, it allows us to impleme=
nt that suggestion I made earlier, where if you provide an rvalue for the i=
nput range to be split, then it will move from that range into internal sto=
rage, so that it's much harder to get pointers/references to temporarie=
s. You wouldn't want to do that for arbitrary containers of anything, b=
ut for strings, yes.<br><br></div></div></blockquote><blockquote class=3D"g=
mail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc sol=
id;padding-left: 1ex;"><div dir=3D"ltr"><div>We should not over-generalize =
what we're making here. I'm sure there's some need to split an =
arbitrary range into subranges based on an equality test of a value. But th=
at should be a different function from splitting a string, based on quality=
-of-life for the resulting code.<br></div></div></blockquote><div><br>Is it=
appropriate to bound the verb `split` tightly with strings now? <br></div>=
</div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/ac2c4208-fb06-4b28-84a9-09c2acce1495%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ac2c4208-fb06-4b28-84a9-09c2acce1495=
%40isocpp.org</a>.<br />
------=_Part_19_2084598420.1482733336182--
------=_Part_18_743172975.1482733336182--
.
Author: FrankHB1989 <frankhb1989@gmail.com>
Date: Sun, 25 Dec 2016 22:25:11 -0800 (PST)
Raw View
------=_Part_2837_135730693.1482733511448
Content-Type: multipart/alternative;
boundary="----=_Part_2838_1191343583.1482733511448"
------=_Part_2838_1191343583.1482733511448
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
=E5=9C=A8 2016=E5=B9=B412=E6=9C=8826=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=80 UT=
C+8=E4=B8=8A=E5=8D=881:34:09=EF=BC=8CVille Voutilainen=E5=86=99=E9=81=93=EF=
=BC=9A
>
> On 25 December 2016 at 19:27, Nicol Bolas <jmck...@gmail.com <javascript:=
>>=20
> wrote:=20
> > We should not over-generalize what we're making here. I'm sure there's=
=20
> some=20
> > need to split an arbitrary range into subranges based on an equality=20
> test of=20
> > a value. But that should be a different function from splitting a=20
> string,=20
> > based on quality-of-life for the resulting code.=20
>
> +1,=20
>
> we already have the over-general version, it's called std::mismatch.=20
> Don't reinvent it, provide=20
> a split that is easy to use, and don't strive for an over-general one=20
> as we already have it.=20
>
That does not justify the opposite approach directly. How to avoid=20
over-specific ones, if any?
=20
There is still a huge gap between `std::mismatch` and your `split`.=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/e8d3ff22-8b36-44c9-b36f-1758f7190084%40isocpp.or=
g.
------=_Part_2838_1191343583.1482733511448
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>=E5=9C=A8 2016=E5=B9=B412=E6=9C=8826=E6=97=A5=E6=
=98=9F=E6=9C=9F=E4=B8=80 UTC+8=E4=B8=8A=E5=8D=881:34:09=EF=BC=8CVille Vouti=
lainen=E5=86=99=E9=81=93=EF=BC=9A<blockquote class=3D"gmail_quote" style=3D=
"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex=
;">On 25 December 2016 at 19:27, Nicol Bolas <<a href=3D"javascript:" ta=
rget=3D"_blank" gdf-obfuscated-mailto=3D"xOzx4vO4CAAJ" rel=3D"nofollow" onm=
ousedown=3D"this.href=3D'javascript:';return true;" onclick=3D"this=
..href=3D'javascript:';return true;">jmck...@gmail.com</a>> wrote=
:
<br>> We should not over-generalize what we're making here. I'm =
sure there's some
<br>> need to split an arbitrary range into subranges based on an equali=
ty test of
<br>> a value. But that should be a different function from splitting a =
string,
<br>> based on quality-of-life for the resulting code.
<br>
<br>+1,
<br>
<br>we already have the over-general version, it's called std::mismatch=
..
<br>Don't reinvent it, provide
<br>a split that is easy to use, and don't strive for an over-general o=
ne
<br>as we already have it.
<br></blockquote><div>That does not justify the opposite approach directly.=
How to avoid over-specific ones, if any?<br>=C2=A0<br></div><div>There is =
still a huge gap between `std::mismatch` and your `split`. <br><br></div></=
div>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/e8d3ff22-8b36-44c9-b36f-1758f7190084%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e8d3ff22-8b36-44c9-b36f-1758f7190084=
%40isocpp.org</a>.<br />
------=_Part_2838_1191343583.1482733511448--
------=_Part_2837_135730693.1482733511448--
.