220 30017 <172d08f0-a3da-4b9e-bfdd-985fb1f527c8@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: join/split for string & string_view
Date: Sun, 25 Dec 2016 07:41:44 -0800 (PST)
Lines: 227
Approved: news@gmane.org
Message-ID: <172d08f0-a3da-4b9e-bfdd-985fb1f527c8@isocpp.org>
References: <f609c0d3-c9ba-4a64-a99f-c2e64091b4e2@isocpp.org>
 <d8544b44-9ed4-403d-a980-6dda516933f6@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_687_533956310.1482680504223"
X-Trace: blaine.gmane.org 1482680513 17993 195.159.176.226 (25 Dec 2016 15:41:53 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 25 Dec 2016 15:41:53 +0000 (UTC)
Cc: lnaltidev@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBOOR77BAKGQEBL3JFMI@isocpp.org Sun Dec 25 16:41:49 2016
Return-path: <std-proposals+bncBCEKFTV6ZUMBBOOR77BAKGQEBL3JFMI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pg0-f72.google.com ([74.125.83.72])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBOOR77BAKGQEBL3JFMI@isocpp.org>)
	id 1cLAvd-00033K-JW
	for gclcip-std-proposals@m.gmane.org; Sun, 25 Dec 2016 16:41:41 +0100
Original-Received: by mail-pg0-f72.google.com with SMTP id u5sf247498187pgi.7
        for <gclcip-std-proposals@m.gmane.org>; Sun, 25 Dec 2016 07:41:46 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=lfswKkVx28gRDh6DJecMB7kl5RZcay8r3Q1Cb8wLsAo=;
        b=YzblX6DejUQoXVf/WFVXSw0C6WdGaNqVx7TghIGMyQTRpiUzUF5NH6SKmYauYavcDm
         XBoAcPOAr7ntrg9OObXZdkI0CSTUfPKKLH4cb9a46z06cNoq1ducG+8i9Shq1gPaiWWY
         9VHkwQyzWS9P67YdFHq+j4Uk8mLfPcVzR3sHdb9FvTSFEvnGWIvffWbSHXSpoHC8oEae
         x+wSi0qTAxgqN2ECTh77ZX7d4rF8C8ZD/SuZp9SJ/A84tEAj8zmaKwjioMnqImv64MM7
         TSX1mFuQPfQZPtqvRJhxWwXF4VHo5ZL9Go6Ph39yaFMUmnynojGPSkWwL7SrpXYCyRSe
         6PBA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=lfswKkVx28gRDh6DJecMB7kl5RZcay8r3Q1Cb8wLsAo=;
        b=WPZvYpe06LOC8t8o+PuWUwI7EXDY80f+gyxk+g81p/0Cfok3NQXrnAkJ9Ug2HYU0/S
         2kYUxQxPn01ppJ8X/2P/J64xhjscBkVYUAQ6KR4DqacNwiZSFr25eRFHjfFil87/C3u2
         DPnuimiU2paogdEU+Pe5bp8CZ/ia1ow2qgb89jq1JkFRhi3md49GAxfFe9t6NKoH/Q/N
         iaAeL9jNVBjyvcXdUjiaFnMvpRJAvLlHODyUPSLiVVM3I2NnkOnnLZA9x7KkyYzYxmxk
         aFJOxvhuwNgE/FIvoO3svwkmOrwIPkmwzaAVIDe7evkgZbViuXBuMmIwOfqsUwB+X7EC
         9dEQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=lfswKkVx28gRDh6DJecMB7kl5RZcay8r3Q1Cb8wLsAo=;
        b=bvHXzpDMFbPHOlmoeD3oaPO9PV0/BSyQjqRp4u2NwbxIiFjXWtM4O5AM1IWnMl3sxr
         c2hPfx/FGFn/VtswWbiYcAQqk+e3a3nCXHEZVVzTpUunk2BQCGmlSvSNDP8a1mruF9jn
         Esha1i7EvEMb1/3/BcakmHGbupxfYPecvQVFvUyMQFgg+MmQNB7TmvSEcSYCqo8DQ09z
         nS6y/hWje7Gc7ivg9Ulodn6MshOjA6eN8129jqgO298V2RnDXJ847tiIGQQWmlcg63NL
         W2EaHWfXVr9M8FTxpjBLTXymV+mp4rgLVqImb8x8YGt82d7sd5NQVChJcsZgP242YJ9z
         x1lg==
X-Gm-Message-State: AIkVDXIiBPZyLoRXBk6a9+2zgDwSBZyVxMklz1ZOQLszsHtKVs1ITjLXqHhSXQJMgyN/0g==
X-Received: by 10.99.2.70 with SMTP id 67mr13688796pgc.42.1482680505843;
        Sun, 25 Dec 2016 07:41:45 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.45.195 with SMTP id g61ls24584524otb.37.gmail; Sun, 25 Dec
 2016 07:41:45 -0800 (PST)
X-Received: by 10.157.51.88 with SMTP id u24mr345571otd.6.1482680504982;
        Sun, 25 Dec 2016 07:41:44 -0800 (PST)
In-Reply-To: <d8544b44-9ed4-403d-a980-6dda516933f6@isocpp.org>
X-Original-Sender: jmckesson@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:30017
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/30017>

------=_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&#39;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 &#39;vector&#39; 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&#39;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&#39;s =
hardly deep metaprogramming magic.<br><br>If you&#39;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&#39;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">&quot;my,csv,l=
ine&quot;</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">&quot;,&quot;</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">&quot;my,c=
sv,line&quot;</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">&quot;,&quot;</=
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`&#39;s constructor (so y=
ou&#39;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">&quot;my,csv,line&quot;</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">&quot;,&quot;</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&#39;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&quot; 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--

.
