220 8672 <6a95bf9c-55c9-4ae2-966f-d1b1f4df6a37@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: string_view::is_null()
Date: Fri, 17 Jan 2014 17:00:12 -0800 (PST)
Lines: 156
Approved: news@gmane.org
Message-ID: <6a95bf9c-55c9-4ae2-966f-d1b1f4df6a37@isocpp.org>
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>
 <8E74B747-7450-41E0-8D1E-48C2D6F81535@gmail.com> <CAGNvRgDH=X2h4K_u3zOu7gUNuQbAcNHGNh=HfCRO9qG1mmiG1w@mail.gmail.com>
 <CANh-dXnytwWwS7E_BGA-xK8E-zw788TJKzM=HJdC-9JbF7+gTQ@mail.gmail.com> <104254A6-C69A-4571-8455-89D7E466D493@gmail.com>
 <CANh-dXngzdnwZZnLRxd=AXQcqLaQky9Cpdw6pkbH8tFqRyZavw@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_2_12412770.1390006812394"
X-Trace: ger.gmane.org 1390006813 28529 80.91.229.3 (18 Jan 2014 01:00:13 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 18 Jan 2014 01:00:13 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCRIRSPDTQIRBHNE46LAKGQE23MMFOA@isocpp.org Sat Jan 18 02:00:20 2014
Return-path: <std-proposals+bncBCRIRSPDTQIRBHNE46LAKGQE23MMFOA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ie0-f197.google.com ([209.85.223.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCRIRSPDTQIRBHNE46LAKGQE23MMFOA@isocpp.org>)
	id 1W4KGl-0006rP-9F
	for gclcip-std-proposals@m.gmane.org; Sat, 18 Jan 2014 02:00:15 +0100
Original-Received: by mail-ie0-f197.google.com with SMTP id e14sf18471488iej.4
        for <gclcip-std-proposals@m.gmane.org>; Fri, 17 Jan 2014 17:00:14 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=zf4/EBQ+iypp0kSNGsfwrSV5PqL7dotn3L91javRxpc=;
        b=BrqEQ1z0ED4UlakCseumc5sEwxHBIrXp3lTJj2226ImeH5pZ2iRx1gzXgMRpHXMl9R
         SF6C42Dms1bzvNGwqyKKynLg0FPst/9ivP7qkOTeJWHwBcBf7bY0xdFuErPiF6eldsul
         6JrQXKhk5hGu0GEnpDzhSGc5cuVsNjA2Nk4bRIV24Bs+2QG7lFU78z1NPwlhOiEtmiMb
         eJala36wc+Q2LBgswZAbueu0Rj2Wbwuhi3baDNPDBD9MV16HUyMT4GftyLYtnNBXFL5M
         auxDU6kYfRpgr9qS0OOVDBrNaWcYA5afVMfiWOFTiErLr0iytDSWrsOj1odKtybVn5JN
         CgqA==
X-Gm-Message-State: ALoCoQmnrzptdKxckZkqUYLhzHSAigYGhy2XRV8t9CbTWuTRl4W4Z8In8EXx75Afd5XMflRaIX3n
X-Received: by 10.182.219.226 with SMTP id pr2mr1921443obc.44.1390006814347;
        Fri, 17 Jan 2014 17:00:14 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.176.202 with SMTP id ck10ls738813igc.1.canary; Fri, 17 Jan
 2014 17:00:13 -0800 (PST)
X-Received: by 10.50.107.67 with SMTP id ha3mr26997igb.7.1390006813497;
        Fri, 17 Jan 2014 17:00:13 -0800 (PST)
In-Reply-To: <CANh-dXngzdnwZZnLRxd=AXQcqLaQky9Cpdw6pkbH8tFqRyZavw@mail.gmail.com>
X-Original-Sender: bengt.gustafsson@beamways.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:8672
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8672>

------=_Part_2_12412770.1390006812394
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

I have not followed this entire thread, instead I hacked up a little=20
implementation which I used in implementing something for another thread on=
=20
an improved "printf" functionality. What I noticed was:

- I had use for a C array of string_view to keep the parts of the original=
=20
string that fell between each data inserted. This means that I must be able=
=20
to default construct string_view as there is no other way to construct an=
=20
array element.
- It is logical to do this default construction by setting m_begin and=20
m_end to nullptr, or m_begin to nullptr and m_size to 0.
- It must be allowed to take a default constructed string_view as the range=
=20
of a range based for statement __or__ to check if the range is in default=
=20
constucted state using something like os_null().

- both of these methods are impossible if the presumptions stated above=20
"begin() should never return nullptr" and "we don't need a special=20
is_null()". Well, not entirely. Of course you could create some bogus=20
object and use its address instead of nullptr.

Someone stated above that the \0 at the end of the string should be=20
accessible even if the string_view is empty. This is clearly impossible as=
=20
a string_view may be constructed as a part of a string which continues on.=
=20
Thus there is no \0 at *end() anytime.

This said I think that the very simple solution is to just set the=20
pointer(s) to nullptr in the default ctor, don't implement any special=20
is_null but return "null" iterators from begin and end in default=20
constructed string_view, which of course results in zero length if they are=
=20
subtracted. I don't really see a problem here, isn't this how all=20
containers do it. For instance a newly default constructed vector? Is the=
=20
issue whether you can rely on this to know wheter the string_view (or=20
vector) has been non-empty before? If so, follow the example of vector and=
=20
give the same promises on the standard level!


Den l=C3=B6rdagen den 18:e januari 2014 kl. 01:06:18 UTC+1 skrev Jeffrey Ya=
sskin:
>
> On Fri, Jan 17, 2014 at 3:51 PM, Marshall Clow <mclow...@gmail.com<javasc=
ript:>>=20
> wrote:=20
> > On Jan 17, 2014, at 2:10 PM, Jeffrey Yasskin <jyas...@google.com<javasc=
ript:>>=20
> wrote:=20
> >=20
> > Agreed. To mitigate this, if string_view::data() could return nullptr, =
I=20
> > believe we could still create strings using std::string(null_sv.begin()=
,=20
> > null_sv.end()).=20
> >=20
> >=20
> > I thought that=E2=80=99s why we had to_string().=20
>
> We have to_string mostly for convenience, I think, although it is=20
> another way to get from a null string_view to a std::string.=20
>

--=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/.

------=_Part_2_12412770.1390006812394
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I have not followed this entire thread, instead I hacked u=
p a little implementation which I used in implementing something for anothe=
r thread on an improved "printf" functionality. What I noticed was:<div><br=
></div><div>- I had use for a C array of string_view to keep the parts of t=
he original string that fell between each data inserted. This means that I =
must be able to default construct string_view as there is no other way to c=
onstruct an array element.</div><div>- It is logical to do this default con=
struction by setting m_begin and m_end to nullptr, or m_begin to nullptr an=
d m_size to 0.</div><div>- It must be allowed to take a default constructed=
 string_view as the range of a range based for statement __or__ to check if=
 the range is in default constucted state using something like os_null().</=
div><div><br></div><div>- both of these methods are impossible if the presu=
mptions stated above "begin() should never return nullptr" and "we don't ne=
ed a special is_null()". Well, not entirely. Of course you could create som=
e bogus object and use its address instead of nullptr.</div><div><br></div>=
<div>Someone stated above that the \0 at the end of the string should be ac=
cessible even if the string_view is empty. This is clearly impossible as a =
string_view may be constructed as a part of a string which continues on. Th=
us there is no \0 at *end() anytime.</div><div><br></div><div>This said I t=
hink that the very simple solution is to just set the pointer(s) to nullptr=
 in the default ctor, don't implement any special is_null but return "null"=
 iterators from begin and end in default constructed string_view, which of =
course results in zero length if they are subtracted. I don't really see a =
problem here, isn't this how all containers do it. For instance a newly def=
ault constructed vector? Is the issue whether you can rely on this to know =
wheter the string_view (or vector) has been non-empty before? If so, follow=
 the example of vector and give the same promises on the standard level!</d=
iv><div><br></div><div><br>Den l=C3=B6rdagen den 18:e januari 2014 kl. 01:0=
6:18 UTC+1 skrev Jeffrey Yasskin:<blockquote class=3D"gmail_quote" style=3D=
"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex=
;">On Fri, Jan 17, 2014 at 3:51 PM, Marshall Clow &lt;<a href=3D"javascript=
:" target=3D"_blank" gdf-obfuscated-mailto=3D"-giuVlTiRDMJ" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'javascript:=
';return true;">mclow...@gmail.com</a>&gt; wrote:
<br>&gt; On Jan 17, 2014, at 2:10 PM, Jeffrey Yasskin &lt;<a href=3D"javasc=
ript:" target=3D"_blank" gdf-obfuscated-mailto=3D"-giuVlTiRDMJ" onmousedown=
=3D"this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'javascr=
ipt:';return true;">jyas...@google.com</a>&gt; wrote:
<br>&gt;
<br>&gt; Agreed. To mitigate this, if string_view::data() could return null=
ptr, I
<br>&gt; believe we could still create strings using std::string(null_sv.be=
gin(),
<br>&gt; null_sv.end()).
<br>&gt;
<br>&gt;
<br>&gt; I thought that=E2=80=99s why we had to_string().
<br>
<br>We have to_string mostly for convenience, I think, although it is
<br>another way to get from a null string_view to a std::string.
<br></blockquote></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 />

------=_Part_2_12412770.1390006812394--

.
