220 8284 <CAPOJ94NDUpX3nF+yPJeDYUZ+27RYA20NcTbbpELdrk_jcUXwpA@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Peter Bigot <bigotp@acm.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: string_view::is_null()
Date: Sun, 29 Dec 2013 12:15:50 -0600
Lines: 212
Approved: news@gmane.org
Message-ID: <CAPOJ94NDUpX3nF+yPJeDYUZ+27RYA20NcTbbpELdrk_jcUXwpA@mail.gmail.com>
References: <8045a4d2-721d-4725-8bb7-7a91b6f53ec8@isocpp.org>
	<186E0927-C962-4E34-AED0-E7509DD1F0A0@gmail.com>
	<ddfcc8e4-aee1-44b5-beca-5401ab86e8a9@isocpp.org>
	<4E250ADA-5977-4F29-94B4-24D9F3E63EC2@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=e89a8ff1cbda307d6304eeb051f6
X-Trace: ger.gmane.org 1388340947 22188 80.91.229.3 (29 Dec 2013 18:15:47 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 29 Dec 2013 18:15:47 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDA3LUEAQACBBV6NQGLAKGQE5COAVUA@isocpp.org Sun Dec 29 19:15:54 2013
Return-path: <std-proposals+bncBDA3LUEAQACBBV6NQGLAKGQE5COAVUA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f198.google.com ([209.85.214.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDA3LUEAQACBBV6NQGLAKGQE5COAVUA@isocpp.org>)
	id 1VxKu0-0007nj-SY
	for gclcip-std-proposals@m.gmane.org; Sun, 29 Dec 2013 19:15:53 +0100
Original-Received: by mail-ob0-f198.google.com with SMTP id wo20sf51384267obc.1
        for <gclcip-std-proposals@m.gmane.org>; Sun, 29 Dec 2013 10:15:51 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:date
         :message-id:subject:from:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=RofPiBSh/g/KOmJgVcJf33ZbiUwzoASRKNqnIOYmGMk=;
        b=PldSQJeOD1Hh4pgKpMKU136cFBi9YRKYADpKjQlicRZ/76g0+PcZUQFNMFBd7ZR83o
         zJmwlpGr/SbTNloYbJz7dre0kHf8UTv2jrLt1e/jOb3c/XPhRPNYHwmyoF6HH9tfzWMQ
         RlmJdqsFBgTHo4zWfO1L8jZt6lw4QRjHOuHfgBgwxfGX2q1WYItXhVI8PYnfhsKbzEGF
         cN9JlpFuUwMxIc8WxQ6JsUHLTOuGde08Pzupai11Uu5Gut62DeXci1/ogI3KlsP+SfHM
         NEQ74MTRq3ltMIn/g5gTwGI5mTwDstT+KZiIqscsLw9soY+D4n3hd8RDuyp3cLHT5cj8
         +xaQ==
X-Gm-Message-State: ALoCoQk5Ce/NkWmd5qRR6CXSTP4YzVR4UD774NBOIcpVxLlMg+WHtkLHQwEFKaqfDqUXa3eAAp62
X-Received: by 10.50.12.68 with SMTP id w4mr25300777igb.0.1388340951705;
        Sun, 29 Dec 2013 10:15:51 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.4.65 with SMTP id i1ls3369636qei.72.gmail; Sun, 29 Dec 2013
 10:15:51 -0800 (PST)
X-Received: by 10.49.127.205 with SMTP id ni13mr105040303qeb.40.1388340951111;
        Sun, 29 Dec 2013 10:15:51 -0800 (PST)
Original-Received: from mail-oa0-x235.google.com (mail-oa0-x235.google.com [2607:f8b0:4003:c02::235])
        by mx.google.com with ESMTPS id e7si38681409qez.74.2013.12.29.10.15.51
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sun, 29 Dec 2013 10:15:51 -0800 (PST)
Received-SPF: pass (google.com: domain of pabigot@gmail.com designates 2607:f8b0:4003:c02::235 as permitted sender) client-ip=2607:f8b0:4003:c02::235;
Original-Received: by mail-oa0-f53.google.com with SMTP id m1so11078850oag.26
        for <std-proposals@isocpp.org>; Sun, 29 Dec 2013 10:15:50 -0800 (PST)
X-Received: by 10.182.199.70 with SMTP id ji6mr41640312obc.36.1388340950628;
 Sun, 29 Dec 2013 10:15:50 -0800 (PST)
Original-Sender: pabigot@gmail.com
Original-Received: by 10.76.168.228 with HTTP; Sun, 29 Dec 2013 10:15:50 -0800 (PST)
In-Reply-To: <4E250ADA-5977-4F29-94B4-24D9F3E63EC2@gmail.com>
X-Original-Sender: bigotp@acm.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of pabigot@gmail.com designates 2607:f8b0:4003:c02::235 as permitted
 sender) smtp.mail=pabigot@gmail.com;       dkim=pass header.i=@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: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:8284
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8284>

--e89a8ff1cbda307d6304eeb051f6
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

On Sun, Dec 29, 2013 at 11:35 AM, Marshall Clow <mclow.lists@gmail.com>wrot=
e:

>
> On Dec 28, 2013, at 11:21 AM, Peter Bigot <bigotp@acm.org> wrote:
>
>
> On Friday, December 27, 2013 11:01:34 PM UTC-6, Marshall wrote:
>>
>> On Dec 27, 2013, at 4:52 AM, abolz...@gmail.com wrote:
>>
> This should not affect data() which returns a non-null pointer.
>>
>> I disagree here with the proposal as currently written.
>> I believe that the requirement that data() always return a non-null
>> pointer is misguided.
>>
>> if sv.size () =3D=3D 0 or sv.empty () [same thing], there is nothing tha=
t you
>> can do with sv.data()
>> (except compare it to null, and that doesn=92t tell you anything useful)=
..
>>
>
> My understanding (which I'd like confirmed) is that sv.data() is still
> useful as it provides a valid position within the referenced object, whic=
h
> might be referenced by other string_view instances or in its native form.
>
>
> a string view refers to a half open range (just like an iterator pair).
> sv.data() a pointer to the beginning of that range, just like sv.begin()
> is an iterator to the beginning of that range.
>

Agreed.


>
> If sv.size() =3D=3D 0, then dereferencing sv.data() or sv.begin() is unde=
fined
> behavior.
>

Agreed.

Also, per [string.view.access] the requirements disallow expression sv[0]
in this case (unlike str[0] if str is a std::string, where the expression
is permitted but the referenced object may not be modified).  A subtlety
worth keeping in mind (libstdc++ missed that one).


>
> Also, I can=92t find anywhere in the specification does it guarantee that
> the following code works:
>
> const char *foo =3D =93abc=94;
> string_view sv1 ( foo, 3 ); // size() =3D=3D 3
>

The definition of the constructor in section x.1 [string.view.cons]
guarantees sv1.data() =3D=3D foo.


> sv1. remove_suffix (3); // size() =3D=3D 0
>

Per [string.view.modifiers] this is equivalent to sv1 =3D sv1.substr(0,
sv1.size() - 3).

Per [string.view.ops] the definition of substr makes the RHS equivalent to
string_view(sv1.data() + 0, sv1.size() - 3).

Same constructor as above, so if that temporary object is tv, tv.data() =3D=
=3D
sv1.data()+0 =3D=3D foo+0 =3D=3D foo.



> assert ( sv1.size() =3D=3D 0);
> assert ( sv1.data() =3D=3D foo ); // will probably work - but might not.
>

AFAICT this must be true.

If my reasoning is wrong, string_view becomes significantly less valuable
to me, so do please point out my error.

FWIW my first reading of N3593 was probably correct and zero-length
string_view values returned from a delimiter find()  may point into the
middle of an input range; they only indicate "not found" when the data()
member references the end position of the input.

Peter

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--e89a8ff1cbda307d6304eeb051f6
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On S=
un, Dec 29, 2013 at 11:35 AM, Marshall Clow <span dir=3D"ltr">&lt;<a href=
=3D"mailto:mclow.lists@gmail.com" target=3D"_blank">mclow.lists@gmail.com</=
a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div style=3D"word-wrap:break-word"><div cla=
ss=3D"im"><br><div><div>On Dec 28, 2013, at 11:21 AM, Peter Bigot &lt;<a hr=
ef=3D"mailto:bigotp@acm.org" target=3D"_blank">bigotp@acm.org</a>&gt; wrote=
:</div>
<br><blockquote type=3D"cite"><div dir=3D"ltr"><br>On Friday, December 27, =
2013 11:01:34 PM UTC-6, Marshall wrote:<blockquote class=3D"gmail_quote" st=
yle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1=
ex">
<div style=3D"word-wrap:break-word">On Dec 27, 2013, at 4:52 AM, <a>abolz..=
..@gmail.com</a> wrote:<br></div></blockquote><blockquote class=3D"gmail_quo=
te" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-=
left:1ex">
<div style=3D"word-wrap:break-word"><div></div><div><blockquote type=3D"cit=
e"><div dir=3D"ltr"><p>This should not affect data() which returns a non-nu=
ll pointer.</p></div></blockquote></div><div>I disagree here with the propo=
sal as currently written.</div>
<div><div>I believe that the requirement that data() always return a non-nu=
ll pointer is misguided.</div><div><br></div></div><div>if sv.size () =3D=
=3D 0 or sv.empty () [same thing], there is nothing that you can do with sv=
..data()</div>
<div>(except compare it to null, and that doesn=92t tell you anything usefu=
l).</div></div></blockquote><div><br>My understanding (which I&#39;d like c=
onfirmed) is that sv.data() is still useful as it provides a valid position=
 within the referenced object, which might be referenced by other string_vi=
ew instances or in its native form.<br>
</div></div></blockquote><div><br></div></div></div>a string view refers to=
 a half open range (just like an iterator pair).<div>sv.data() a pointer to=
 the beginning of that range, just like sv.begin() is an iterator to the be=
ginning of that range.</div>
</div></blockquote><div><br></div><div>Agreed.<br>=A0<br></div><blockquote =
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid=
;padding-left:1ex"><div style=3D"word-wrap:break-word"><div><br></div><div>=
If sv.size() =3D=3D 0, then dereferencing sv.data() or sv.begin() is undefi=
ned behavior.</div>
</div></blockquote><div><br></div><div>Agreed.<br><br>Also, per [string.vie=
w.access] the requirements disallow expression sv[0] in this case (unlike s=
tr[0] if str is a std::string, where the expression is permitted but the re=
ferenced object may not be modified).=A0 A subtlety worth keeping in mind (=
libstdc++ missed that one).<br>
=A0<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;b=
order-left:1px #ccc solid;padding-left:1ex"><div style=3D"word-wrap:break-w=
ord"><div><br></div><div>Also, I can=92t find anywhere in the specification=
 does it guarantee that the following code works:</div>
<div><br></div><div><span style=3D"white-space:pre-wrap">	</span>const char=
 *foo =3D =93abc=94;</div><div><span style=3D"white-space:pre-wrap">	</span=
>string_view sv1 ( foo, 3 );<span style=3D"white-space:pre-wrap">	</span>//=
 size() =3D=3D 3</div>
</div></blockquote><div><br></div><div>The definition of the constructor in=
 section x.1 [string.view.cons] guarantees sv1.data() =3D=3D foo.<br>=A0<br=
></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-=
left:1px #ccc solid;padding-left:1ex">
<div style=3D"word-wrap:break-word"><div><span style=3D"white-space:pre-wra=
p">	</span>sv1.=A0remove_suffix (3);<span style=3D"white-space:pre-wrap">	<=
/span>// size() =3D=3D 0</div></div></blockquote><div><br></div><div>Per [s=
tring.view.modifiers] this is equivalent to sv1 =3D sv1.substr(0, sv1.size(=
) - 3).<br>
<br>Per [string.view.ops] the definition of substr makes the RHS equivalent=
 to string_view(sv1.data() + 0, sv1.size() - 3).<br><br>Same constructor as=
 above, so if that temporary object is tv, tv.data() =3D=3D sv1.data()+0 =
=3D=3D foo+0 =3D=3D foo.<br>
<br></div><div></div><div>=A0</div><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div sty=
le=3D"word-wrap:break-word"><div><span style=3D"white-space:pre-wrap">	</sp=
an>assert ( sv1.size() =3D=3D 0);<span style=3D"white-space:pre-wrap">	</sp=
an></div>
<div><span style=3D"white-space:pre-wrap">	</span>assert ( sv1.data() =3D=
=3D foo );<span style=3D"white-space:pre-wrap">	</span>// will probably wor=
k - but might not.</div></div></blockquote><div><br></div><div>AFAICT this =
must be true.<br>
<br></div><div>If my reasoning is wrong, string_view becomes significantly =
less valuable to me, so do please point out my error.<br></div><div><br></d=
iv><div>FWIW my first reading of N3593 was probably correct and zero-length=
 string_view values returned from a delimiter find()=A0 may point into the =
middle of an input range; they only indicate &quot;not found&quot; when the=
 data() member references the end position of the input.<br>
</div><div>=A0<br></div></div>Peter<br></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--e89a8ff1cbda307d6304eeb051f6--

.
