220 8658 <8E74B747-7450-41E0-8D1E-48C2D6F81535@gmail.com> article
Path: news.gmane.org!not-for-mail
From: Marshall Clow <mclow.lists@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: string_view::is_null()
Date: Fri, 17 Jan 2014 13:55:41 -0800
Lines: 181
Approved: news@gmane.org
Message-ID: <8E74B747-7450-41E0-8D1E-48C2D6F81535@gmail.com>
References: <8045a4d2-721d-4725-8bb7-7a91b6f53ec8@isocpp.org> <186E0927-C962-4E34-AED0-E7509DD1F0A0@gmail.com> <7aad44d8-6b4e-438a-b309-bd898b994b34@isocpp.org> <9C2C439F-7983-4224-B272-53CAD0E2E456@gmail.com> <CANh-dXnYg=1kmm1nJdSnTXmYyfBxbLTD9b+wecT+eZm5nPkf2A@mail.gmail.com> <CAGg_6+Pz0gQQcY_Vq6LTMFc-4iOJvVN1O3jc3gjh0J2egBTgGg@mail.gmail.com> <CANh-dX=Dr35_jvxadm2HWxNk6e87y8V+Dkyiw+syBfgfdTfobw@mail.gmail.com> <CAPOJ94O19N207rjm73tKJSc7K55kOzYxHbY9wtXquk=_uqqMsA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 7.1 \(1827\))
Content-Type: multipart/alternative; boundary="Apple-Mail=_6DD81798-CFCD-4E3C-8C18-83A4B141E511"
X-Trace: ger.gmane.org 1389995743 11077 80.91.229.3 (17 Jan 2014 21:55:43 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 17 Jan 2014 21:55:43 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDHIXP53REBRBYON42LAKGQEXUFOZKI@isocpp.org Fri Jan 17 22:55:49 2014
Return-path: <std-proposals+bncBDHIXP53REBRBYON42LAKGQEXUFOZKI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pb0-f70.google.com ([209.85.160.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDHIXP53REBRBYON42LAKGQEXUFOZKI@isocpp.org>)
	id 1W4HOF-0001Z9-Hg
	for gclcip-std-proposals@m.gmane.org; Fri, 17 Jan 2014 22:55:47 +0100
Original-Received: by mail-pb0-f70.google.com with SMTP id rq2sf2346955pbb.1
        for <gclcip-std-proposals@m.gmane.org>; Fri, 17 Jan 2014 13:55:46 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:mime-version:subject:date
         :references:to:in-reply-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=hjiXRAZPhIGj3aWtPpXgWqvCf+v2zj40O3M6WdmmV5Y=;
        b=fM1YbWx98nzzBvz+RvldIu4kLw3+uFkG+/nRxBeghtsjA/FdRGFuwXVKBUEiX9fcZu
         nc355vaSsFlsM/nHNQjCLhNztfnzcYeEFVf96gu8c9ul5l4ClWt7sfvKSXSXkuq52mJK
         TpnDkuzdJ3DECa4fFyDZi45+PE5art+RrAXNXGRGHj/Xk2XJFsqcUdAEV1o4X9nbeQVB
         7AzVsEoMa0JRCofP7jyDutqPPbbG9j2xS/vD8SXONNAzcah2sJudImbkKxe+TO9JC1mq
         ioqLzF86yjp/X2k0cw3IOkxFLnK1O4TkIINr7Ervp9NycFcd8S5A+3FoixT2jKZ4nqwa
         FN4Q==
X-Gm-Message-State: ALoCoQmtTXoLjuOMqJ+YvPGxEfhXUL39lttVKzSB5W0uDx1C3/Z5Ibfo/MtzFJCAdXurinNTyehb
X-Received: by 10.66.193.104 with SMTP id hn8mr1671145pac.46.1389995746359;
        Fri, 17 Jan 2014 13:55:46 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.96.69 with SMTP id dq5ls724566qeb.85.gmail; Fri, 17 Jan
 2014 13:55:45 -0800 (PST)
X-Received: by 10.236.147.107 with SMTP id s71mr3912908yhj.45.1389995745718;
        Fri, 17 Jan 2014 13:55:45 -0800 (PST)
Original-Received: from mail-ob0-x22a.google.com (mail-ob0-x22a.google.com [2607:f8b0:4003:c01::22a])
        by mx.google.com with ESMTPS id q66si4069978yhm.154.2014.01.17.13.55.45
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Fri, 17 Jan 2014 13:55:45 -0800 (PST)
Received-SPF: pass (google.com: domain of mclow.lists@gmail.com designates 2607:f8b0:4003:c01::22a as permitted sender) client-ip=2607:f8b0:4003:c01::22a;
Original-Received: by mail-ob0-f170.google.com with SMTP id va2so1317947obc.1
        for <std-proposals@isocpp.org>; Fri, 17 Jan 2014 13:55:45 -0800 (PST)
X-Received: by 10.182.230.135 with SMTP id sy7mr3699042obc.24.1389995745265;
        Fri, 17 Jan 2014 13:55:45 -0800 (PST)
Original-Received: from [192.168.16.50] (wsip-174-77-164-131.sd.sd.cox.net. [174.77.164.131])
        by mx.google.com with ESMTPSA id qe2sm14225384obc.1.2014.01.17.13.55.43
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Fri, 17 Jan 2014 13:55:44 -0800 (PST)
In-Reply-To: <CAPOJ94O19N207rjm73tKJSc7K55kOzYxHbY9wtXquk=_uqqMsA@mail.gmail.com>
X-Mailer: Apple Mail (2.1827)
X-Original-Sender: mclow.lists@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of mclow.lists@gmail.com designates 2607:f8b0:4003:c01::22a as
 permitted sender) smtp.mail=mclow.lists@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=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:8658
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8658>

--Apple-Mail=_6DD81798-CFCD-4E3C-8C18-83A4B141E511
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=windows-1252


On Jan 17, 2014, at 1:25 PM, Peter Bigot <bigotp@acm.org> wrote:

> On Fri, Jan 17, 2014 at 2:22 PM, Jeffrey Yasskin <jyasskin@google.com> wr=
ote:
> On Fri, Jan 17, 2014 at 12:18 PM, Nevin Liber <nevin@eviloverlord.com> wr=
ote:
> > On 17 January 2014 14:11, Jeffrey Yasskin <jyasskin@google.com> wrote:
> >>
> >> If it is, I intend to also
> >> remove the precondition on the string_view(data, size) to let people
> >> explicitly put nullptr in.
> >
> >
> > I'd like to, mainly because it makes it easy to create a string_view fr=
om a
> > vector<char> by using v.data() and v.size().  Having to special case a =
check
> > for nullptr (such as in string::string(const char*, size_t)) for what i=
s
> > otherwise a perfectly valid 0-sized range is just annoying.
>=20
> Ah, vector.data() doesn't guarantee non-null results. :( That's a good ar=
gument.
>=20
> First, is that true?  [data(), data()+size()) must be a valid range, but =
I've been unable to find a definition of "valid range" in the standard so I=
 could understand whether an empty valid range permits its base to be a nul=
l pointer.
>=20
> Second, even if so std::string.data() does guarantee a non-null result, d=
oesn't it?  In that case it's also required that data()+i =3D=3D &operator[=
](i) for i in [0, size()] which led me to believe data() could not be null,=
 since the equality must hold for i=3D=3D0 and operator[] must return a ref=
erence to an object (hence the underlying pointer cannot be null).

I think you mean, [0,i), not [0,i]

> I've been swayed by the argument that there's no such thing as a null std=
::string, so there should be no such thing as a null std::string_view.  Thi=
s is easily assured by disallowing std::string_view(s, n) for a null s just=
 as std::string(s, n) is disallowed for null s.

The difference here is that string manages its own storage, while string_vi=
ew does not.

> I don't see it as unreasonable to require a check for that situation befo=
re creating a std::string_view in situations where a char* pointer comes fr=
om a source that might produce a null pointer.  As Nevin points out, you ha=
ve to do it for std::string too.

Maybe I missed something earlier in the discussion, but I believe that
	std::string foo { nullptr, 0 };

is a perfectly legal way of creating an empty string.

Section 21.4.2 says only:
	basic_string(const charT* s, size_type n,
        	     const Allocator& a =3D Allocator());
	Requires: s points to an array of at least n elements of charT.


> Personally, I'd find it more annoying to have to constantly check in ever=
y utility function that operates on string_view instances whether an input =
sv.data() is null in addition to whether sv.size() is zero.=20

I=92m afraid I don=92t see why you would do this. Can you give an example, =
please?

=97 Marshall

--=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/.

--Apple-Mail=_6DD81798-CFCD-4E3C-8C18-83A4B141E511
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=windows-1252

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jan 1=
7, 2014, at 1:25 PM, Peter Bigot &lt;<a href=3D"mailto:bigotp@acm.org">bigo=
tp@acm.org</a>&gt; wrote:</div><br class=3D"Apple-interchange-newline"><blo=
ckquote type=3D"cite"><div dir=3D"ltr"><div class=3D"gmail_extra"><div clas=
s=3D"gmail_quote">On Fri, Jan 17, 2014 at 2:22 PM, Jeffrey Yasskin <span di=
r=3D"ltr">&lt;<a href=3D"mailto:jyasskin@google.com" target=3D"_blank">jyas=
skin@google.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 class=3D"im">On Fri, Jan 17, 2014 at 12=
:18 PM, Nevin Liber &lt;<a href=3D"mailto:nevin@eviloverlord.com">nevin@evi=
loverlord.com</a>&gt; wrote:<br>

&gt; On 17 January 2014 14:11, Jeffrey Yasskin &lt;<a href=3D"mailto:jyassk=
in@google.com">jyasskin@google.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; If it is, I intend to also<br>
&gt;&gt; remove the precondition on the string_view(data, size) to let peop=
le<br>
&gt;&gt; explicitly put nullptr in.<br>
&gt;<br>
&gt;<br>
&gt; I'd like to, mainly because it makes it easy to create a string_view f=
rom a<br>
&gt; vector&lt;char&gt; by using v.data() and v.size(). &nbsp;Having to spe=
cial case a check<br>
&gt; for nullptr (such as in string::string(const char*, size_t)) for what =
is<br>
&gt; otherwise a perfectly valid 0-sized range is just annoying.<br></div><=
/blockquote><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bo=
rder-left:1px #ccc solid;padding-left:1ex"><div class=3D"im">
<br>
</div>Ah, vector.data() doesn't guarantee non-null results. :( That's a goo=
d argument.<br></blockquote><div><br></div><div>First, is that true?&nbsp; =
[data(), data()+size()) must be a valid range, but I've been unable to find=
 a definition of "valid range" in the standard so I could understand whethe=
r an empty valid range permits its base to be a null pointer.<br>
</div></div><br></div><div class=3D"gmail_extra">Second, even if so std::st=
ring.data() does guarantee a non-null result, doesn't it?&nbsp; In that cas=
e it's also required that data()+i =3D=3D &amp;operator[](i) for i in [0, s=
ize()] which led me to believe data() could not be null, since the equality=
 must hold for i=3D=3D0 and operator[] must return a reference to an object=
 (hence the underlying pointer cannot be null).<br></div></div></blockquote=
><div><br></div>I think you mean, [0,i), not [0,i]</div><div><br></div><div=
><blockquote type=3D"cite"><div dir=3D"ltr"><div class=3D"gmail_extra">I've=
 been swayed by the argument that there's no such thing as a null std::stri=
ng, so there should be no such thing as a null std::string_view.&nbsp; This=
 is easily assured by disallowing std::string_view(s, n) for a null s just =
as std::string(s, n) is disallowed for null s.<br></div></div></blockquote>=
<div><br></div>The difference here is that string manages its own storage, =
while string_view does not.</div><div><br><blockquote type=3D"cite"><div di=
r=3D"ltr"><div class=3D"gmail_extra">I don't see it as unreasonable to requ=
ire a check for that situation before creating a std::string_view in situat=
ions where a char* pointer comes from a source that might produce a null po=
inter.&nbsp; As Nevin points out, you have to do it for std::string too.<br=
></div></div></blockquote><div><br></div>Maybe I missed something earlier i=
n the discussion, but I believe that</div><div><span class=3D"Apple-tab-spa=
n" style=3D"white-space:pre">	</span>std::string foo { nullptr, 0 };</div><=
div><br></div><div>is a perfectly legal way of creating an empty string.</d=
iv><div><br></div><div>Section 21.4.2 says only:</div><div><span class=3D"A=
pple-tab-span" style=3D"white-space:pre">	</span>basic_string(const charT* =
s, size_type n,<br><div>&nbsp; &nbsp; &nbsp; &nbsp; <span class=3D"Apple-ta=
b-span" style=3D"white-space:pre">	</span>&nbsp; &nbsp; &nbsp;const Allocat=
or&amp; a =3D Allocator());</div><div><span class=3D"Apple-tab-span" style=
=3D"white-space:pre">	</span>Requires:&nbsp;s&nbsp;points to an array of at=
 least&nbsp;n&nbsp;elements of&nbsp;charT.</div><div><br></div></div><div><=
br><blockquote type=3D"cite"><div dir=3D"ltr"><div class=3D"gmail_extra">Pe=
rsonally, I'd find it more annoying to have to constantly check in every ut=
ility function that operates on string_view instances whether an input sv.d=
ata() is null in addition to whether sv.size() is zero.&nbsp; </div></div><=
/blockquote><div><br></div>I=92m afraid I don=92t see why you would do this=
.. Can you give an example, please?</div><div><br></div><div>=97 Marshall</d=
iv><div><br></div></body></html>

<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 />

--Apple-Mail=_6DD81798-CFCD-4E3C-8C18-83A4B141E511--

.
