220 8673 <336403ba-e7da-4fca-99f9-de91492327b5@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:12:23 -0800 (PST)
Lines: 190
Approved: news@gmane.org
Message-ID: <336403ba-e7da-4fca-99f9-de91492327b5@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>
 <6a95bf9c-55c9-4ae2-966f-d1b1f4df6a37@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_13_21255250.1390007543036"
X-Trace: ger.gmane.org 1390007539 2658 80.91.229.3 (18 Jan 2014 01:12:19 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 18 Jan 2014 01:12:19 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCRIRSPDTQIRB6FJ46LAKGQE2N25MKA@isocpp.org Sat Jan 18 02:12:27 2014
Return-path: <std-proposals+bncBCRIRSPDTQIRB6FJ46LAKGQE2N25MKA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qe0-f71.google.com ([209.85.128.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCRIRSPDTQIRB6FJ46LAKGQE2N25MKA@isocpp.org>)
	id 1W4KSX-0001g8-Rj
	for gclcip-std-proposals@m.gmane.org; Sat, 18 Jan 2014 02:12:26 +0100
Original-Received: by mail-qe0-f71.google.com with SMTP id 8sf7770191qea.10
        for <gclcip-std-proposals@m.gmane.org>; Fri, 17 Jan 2014 17:12:25 -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=Z2CHDV+r7tdQAyEwoWQF5x7y2svjsyKWaW7UpvfZ2CQ=;
        b=Wm5k1CCzEyWrXrG3f+EDJ88MaE+shBR4JurV5+KcChM0AzCZxcNSLmT09HMlXidWak
         kFiJ+qBcfrfoPZxJgultQKk+VVtcc6VW8G7rxfIxKlJejj60sKTj7rKgMoO1YNtHwJyo
         Zx5PwUMiJT4omF7ywshhC0+sme30HVeB0KihzbM+r08aP7GX80hNOsfOkazkXSif4/+x
         6zBFfv6V9D3V2zWM6BNISH+sqtGA+lbms9nQ21SSZkdJh0E5jal6uZUw8rZg3kU3/+m6
         0MmWZTA8sNxAyC89xpxFC1lW4eb65imzE1+43OoT0p107fM0iKln45LBpjrUy9ZGNDyE
         UoQg==
X-Gm-Message-State: ALoCoQku8XvQxXXXeBT3nYy94HFs1Wpmg/rJHS70EnkFt1d56dHBfjSSN1lb5m0c3FTUp29ENvu0
X-Received: by 10.58.134.15 with SMTP id pg15mr1908665veb.14.1390007545000;
        Fri, 17 Jan 2014 17:12:25 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.239.165 with SMTP id vt5ls751588igc.6.gmail; Fri, 17 Jan
 2014 17:12:24 -0800 (PST)
X-Received: by 10.50.253.195 with SMTP id ac3mr27723igd.15.1390007544240;
        Fri, 17 Jan 2014 17:12:24 -0800 (PST)
In-Reply-To: <6a95bf9c-55c9-4ae2-966f-d1b1f4df6a37@isocpp.org>
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:8673
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8673>

------=_Part_13_21255250.1390007543036
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Someone said that constructing a string from (nullpltr, 0) is not allowed,=
=20
and that is used as an argument here. How about looking into why this is=20
not allowed first? I can't see any practical reason for string nor for=20
string_view.

Someone else claimed that if nullptr could be returned from data() then=20
you'd have to test for this in _addition_ to testing for size() =3D=3D 0. I=
=20
can't understand ahy as if size() is 0 there is exactly 0 offsets at which=
=20
it is ok to dereference the pointer returned from data. This is more=20
information you get from testing whether the returned pointer is nullptr,=
=20
i.e. even if data() returned non-null there may be no elements to access,=
=20
but if size() returns 0 there can be _no_ elements whether the pointer is=
=20
null or not.


Den l=C3=B6rdagen den 18:e januari 2014 kl. 02:00:12 UTC+1 skrev Bengt=20
Gustafsson:
>
> 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 origina=
l=20
> string that fell between each data inserted. This means that I must be ab=
le=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=20
> range of a range based for statement __or__ to check if the range is in=
=20
> default 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 a=
s=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 a=
re=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 an=
d=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=
=20
> Yasskin:
>>
>> On Fri, Jan 17, 2014 at 3:51 PM, Marshall Clow <mclow...@gmail.com>=20
>> wrote:=20
>> > On Jan 17, 2014, at 2:10 PM, Jeffrey Yasskin <jyas...@google.com>=20
>> wrote:=20
>> >=20
>> > Agreed. To mitigate this, if string_view::data() could return nullptr,=
=20
>> I=20
>> > believe we could still create strings using=20
>> 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_13_21255250.1390007543036
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Someone said that constructing a string from (nullpltr, 0)=
 is not allowed, and that is used as an argument here. How about looking in=
to why this is not allowed first? I can't see any practical reason for stri=
ng nor for string_view.<div><br></div><div>Someone else claimed that if nul=
lptr could be returned from data() then you'd have to test for this in _add=
ition_ to testing for size() =3D=3D 0. I can't understand ahy as if size() =
is 0 there is exactly 0 offsets at which it is ok to dereference the pointe=
r returned from data. This is more information you get from testing whether=
 the returned pointer is nullptr, i.e. even if data() returned non-null the=
re may be no elements to access, but if size() returns 0 there can be _no_ =
elements whether the pointer is null or not.</div><div><br></div><div><br><=
/div><div>Den l=C3=B6rdagen den 18:e januari 2014 kl. 02:00:12 UTC+1 skrev =
Bengt Gustafsson:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">I have not followed this entire thread, instead I hacked up a little im=
plementation which I used in implementing something for another thread on a=
n 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 the original s=
tring 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 construct an a=
rray element.</div><div>- It is logical to do this default construction by =
setting m_begin and m_end to nullptr, or m_begin to nullptr and 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 presumptions state=
d above "begin() should never return nullptr" and "we don't need a special =
is_null()". Well, not entirely. Of course you could create some bogus objec=
t 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 accessible even=
 if the string_view is empty. This is clearly impossible as a string_view m=
ay be constructed as a part of a string which continues on. Thus there is n=
o \0 at *end() anytime.</div><div><br></div><div>This said I think that the=
 very simple solution is to just set the pointer(s) to nullptr in the defau=
lt ctor, don't implement any special is_null but return "null" iterators fr=
om begin and end in default constructed string_view, which of course result=
s 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 default construc=
ted vector? Is the issue whether you can rely on this to know wheter the st=
ring_view (or vector) has been non-empty before? If so, follow the example =
of vector and give the same promises on the standard level!</div><div><br><=
/div><div><br>Den l=C3=B6rdagen den 18:e januari 2014 kl. 01:06:18 UTC+1 sk=
rev Jeffrey Yasskin:<blockquote class=3D"gmail_quote" style=3D"margin:0;mar=
gin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, Jan 17,=
 2014 at 3:51 PM, Marshall Clow &lt;<a>mclow...@gmail.com</a>&gt; wrote:
<br>&gt; On Jan 17, 2014, at 2:10 PM, Jeffrey Yasskin &lt;<a>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></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_13_21255250.1390007543036--

.
