220 8647 <9C2C439F-7983-4224-B272-53CAD0E2E456@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 08:26:50 -0800
Lines: 109
Approved: news@gmane.org
Message-ID: <9C2C439F-7983-4224-B272-53CAD0E2E456@gmail.com>
References: <8045a4d2-721d-4725-8bb7-7a91b6f53ec8@isocpp.org> <186E0927-C962-4E34-AED0-E7509DD1F0A0@gmail.com> <7aad44d8-6b4e-438a-b309-bd898b994b34@isocpp.org>
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=_769C02A7-776F-4F23-B5F6-273D5042B65C"
X-Trace: ger.gmane.org 1389976013 31932 80.91.229.3 (17 Jan 2014 16:26:53 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 17 Jan 2014 16:26:53 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDHIXP53REBRBUNT4WLAKGQEDTVW5TY@isocpp.org Fri Jan 17 17:27:00 2014
Return-path: <std-proposals+bncBDHIXP53REBRBUNT4WLAKGQEDTVW5TY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qc0-f197.google.com ([209.85.216.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDHIXP53REBRBUNT4WLAKGQEDTVW5TY@isocpp.org>)
	id 1W4CG2-00006P-EA
	for gclcip-std-proposals@m.gmane.org; Fri, 17 Jan 2014 17:26:58 +0100
Original-Received: by mail-qc0-f197.google.com with SMTP id e16sf6536530qcx.0
        for <gclcip-std-proposals@m.gmane.org>; Fri, 17 Jan 2014 08:26:57 -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=lAc7lZ+w5neqkeXwqofmlr9Tz7Bjom+AyXaMTyJlzyk=;
        b=RqsjxXtBbQQgtJEsvC/oj1vHCE7z2gX8hg00H/VP7a35lXn0wtYl6UZa+w7fLyNNUx
         BjeWKk/zvLQCf/JiAEMxP/hqG42gZ/hQr4qT2D0rX2sIUwqI25xw5fj22MEWzCyMailE
         RTbf30G+lZaTzlMgO+vr5etbK6Qami9YSMqWFfhf+QugmiW8JWwd2pEHusiXJEI4t/47
         JaNzC1j+jtqXSomCM7HCNarskNVPLiQXGMSkVdNlAhQ5IIFu9BViDUQ3c52alP45mdYt
         0m/7J0xoo298T5Y/FNf5LhJVON1y5CC3uLwQna0LsGWFIJAwG80Acg6fRjGww5gpWXNB
         Blyw==
X-Gm-Message-State: ALoCoQnVwv0BUyQqfVvjfGWDVHKJ+UMmnFPA0IFMagEeIihDvyTHVUOHM0Bt1k9K+11+aOg3SzvZ
X-Received: by 10.236.94.113 with SMTP id m77mr969299yhf.33.1389976017622;
        Fri, 17 Jan 2014 08:26:57 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.95.134 with SMTP id i6ls488020qge.2.gmail; Fri, 17 Jan
 2014 08:26:57 -0800 (PST)
X-Received: by 10.236.131.19 with SMTP id l19mr2767484yhi.0.1389976017058;
        Fri, 17 Jan 2014 08:26:57 -0800 (PST)
Original-Received: from mail-pb0-x236.google.com (mail-pb0-x236.google.com [2607:f8b0:400e:c01::236])
        by mx.google.com with ESMTPS id q69si15893268yhd.220.2014.01.17.08.26.56
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Fri, 17 Jan 2014 08:26:57 -0800 (PST)
Received-SPF: pass (google.com: domain of mclow.lists@gmail.com designates 2607:f8b0:400e:c01::236 as permitted sender) client-ip=2607:f8b0:400e:c01::236;
Original-Received: by mail-pb0-f54.google.com with SMTP id uo5so656043pbc.13
        for <std-proposals@isocpp.org>; Fri, 17 Jan 2014 08:26:55 -0800 (PST)
X-Received: by 10.68.17.41 with SMTP id l9mr3106999pbd.76.1389976015894;
        Fri, 17 Jan 2014 08:26:55 -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 nl7sm23985319pbc.6.2014.01.17.08.26.54
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Fri, 17 Jan 2014 08:26:54 -0800 (PST)
In-Reply-To: <7aad44d8-6b4e-438a-b309-bd898b994b34@isocpp.org>
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:400e:c01::236 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:8647
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8647>

--Apple-Mail=_769C02A7-776F-4F23-B5F6-273D5042B65C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=windows-1252

On Jan 15, 2014, at 4:28 AM, Olaf van der Spek <olafvdspek@gmail.com> wrote=
:

> On Saturday, December 28, 2013 6:01:34 AM UTC+1, Marshall wrote:
> if sv.size () =3D=3D 0 or sv.empty () [same thing], there is nothing that=
 you can do with sv.data()
> (except compare it to null, and that doesn=92t tell you anything useful).
>=20
> Are you sure?
> IMO an empty string_view could still point into a string and I should be =
able to use that pointer to for example construct a new string_view.


A string view references a half-open contiguous range of characters; [ data=
(), data()+size())

if size() =3D=3D 0, then the range of characters referenced by the string v=
iew is empty, and accessing them (either via dereferencing begin() or data(=
)) is (or should be) undefined behavior. (the same as any other container)

If in your program, you =93know=94 that the pointer returned by data() poin=
ts to something valid, well, that=92s on you to determine.

Code example:

	char deref ( string_view sv ) { return *sv.data(); }

	string_view sv1;
	string_view sv2 { =93ABCDE=94 };
	sv2.remove_prefix(5);
	assert ( sv1 =3D=3D sv2 );
	deref ( sv1 );	// may or may not blow up in your face
	deref ( sv2 );	// this will probably =93work=94 ; but I don=92t know what =
it will return.

=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=_769C02A7-776F-4F23-B5F6-273D5042B65C
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;">On Jan 15, 2014, at 4:=
28 AM, Olaf van der Spek &lt;<a href=3D"mailto:olafvdspek@gmail.com">olafvd=
spek@gmail.com</a>&gt; wrote:<br><div><br class=3D"Apple-interchange-newlin=
e"><blockquote type=3D"cite"><div dir=3D"ltr">On Saturday, December 28, 201=
3 6:01:34 AM UTC+1, Marshall wrote:<blockquote class=3D"gmail_quote" style=
=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: =
1ex;"><div style=3D"word-wrap:break-word"><div>if sv.size () =3D=3D 0 or sv=
..empty () [same thing], there is nothing that you can do with sv.data()</di=
v><div>(except compare it to null, and that doesn=92t tell you anything use=
ful).</div></div></blockquote><div><br></div><div>Are you sure?</div><div>I=
MO an empty string_view could still point into a string and I should be abl=
e to use that pointer to for example construct a new string_view.</div></di=
v></blockquote></div><div><br></div><div>A string view references a half-op=
en contiguous range of characters; [ data(), data()+size())</div><div><br><=
/div><div>if size() =3D=3D 0, then the range of characters referenced by th=
e string view is empty, and accessing them (either via dereferencing begin(=
) or data()) is (or should be) undefined behavior. (the same as any other c=
ontainer)</div><div><br></div><div>If in your program, you =93know=94 that =
the pointer returned by data() points to something valid, well, that=92s on=
 you to determine.</div><div><br></div><div>Code example:</div><div><br></d=
iv><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>ch=
ar deref ( string_view sv ) { return *sv.data(); }</div><div><br></div><div=
><span class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>string_vi=
ew sv1;</div><div><span class=3D"Apple-tab-span" style=3D"white-space:pre">=
	</span>string_view sv2 { =93ABCDE=94 };</div><div><span class=3D"Apple-tab=
-span" style=3D"white-space:pre">	</span>sv2.remove_prefix(5);</div><div><s=
pan class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>assert ( sv1=
 =3D=3D sv2 );</div><div><span class=3D"Apple-tab-span" style=3D"white-spac=
e:pre">	</span>deref ( sv1 );<span class=3D"Apple-tab-span" style=3D"white-=
space:pre">	</span>// may or may not blow up in your face</div><div><span c=
lass=3D"Apple-tab-span" style=3D"white-space:pre">	</span>deref ( sv2 );<sp=
an class=3D"Apple-tab-span" style=3D"white-space:pre">	</span>// this will =
probably =93work=94 ; but I don=92t know what it will return.</div><div><br=
></div><div>=97 Marshall</div><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=_769C02A7-776F-4F23-B5F6-273D5042B65C--

.
