220 8287 <CANh-dXmKgq7rvO7fUoA=rddXog98Pj6Ef2w8LpctBwqUTjVH9g@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Jeffrey Yasskin <jyasskin@google.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: string_view::is_null()
Date: Sun, 29 Dec 2013 20:07:21 -0800
Lines: 112
Approved: news@gmane.org
Message-ID: <CANh-dXmKgq7rvO7fUoA=rddXog98Pj6Ef2w8LpctBwqUTjVH9g@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> <CAPOJ94NDUpX3nF+yPJeDYUZ+27RYA20NcTbbpELdrk_jcUXwpA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1388376456 28100 80.91.229.3 (30 Dec 2013 04:07:36 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 30 Dec 2013 04:07:36 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDDM34EO6QDRBDPDQOLAKGQEJ5FGT4Q@isocpp.org Mon Dec 30 05:07:44 2013
Return-path: <std-proposals+bncBDDM34EO6QDRBDPDQOLAKGQEJ5FGT4Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f200.google.com ([209.85.214.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDDM34EO6QDRBDPDQOLAKGQEJ5FGT4Q@isocpp.org>)
	id 1VxU8l-0004M5-PX
	for gclcip-std-proposals@m.gmane.org; Mon, 30 Dec 2013 05:07:44 +0100
Original-Received: by mail-ob0-f200.google.com with SMTP id wm4sf53054275obc.11
        for <gclcip-std-proposals@m.gmane.org>; Sun, 29 Dec 2013 20:07:42 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20120113;
        h=mime-version:in-reply-to:references:from:date:message-id:subject: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
         :content-transfer-encoding;
        bh=+sMHIvpNTc4LLJ55LPt91T/k4P6Zr/AICOuhAj5KFzA=;
        b=E1uvqCHG4xyUYEWShV3LACFDOEt0JzUbDqpQK33HPinTu+NYHWYvFxGGi8kP8EYtiJ
         6mJqYaAP4rzATT1LN456SEM5U2CTXn30czUvEHrSD7eHhmHWkB+Gve3J30ytw5t9//+v
         U/ZZkAdvx1bbU7HaLDZ1u2qb2/VoEqoEbYluT/BT7k7y7MPu8O6ywpHmy2umDJavVhti
         DQxac79nfRobFhMmwBop+i4P4A4HkvRv/IFjR2gxFROeBML3cpex3f11jI6dapCpVAmw
         rx9/xXBChJHAuMpdRa1DzEx0OXHFPCsqguPxOu1uVXqdOR0uKQErVrs0ncfLmHDvhcNM
         fOGw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject: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:content-transfer-encoding;
        bh=+sMHIvpNTc4LLJ55LPt91T/k4P6Zr/AICOuhAj5KFzA=;
        b=IQV/UcPP9uYenPOHEiPrkAueUvpwdPFl7zbIlgBCV+4y0hKh/+UebSH1sil8Rh7W03
         Qk/U0ZvhBq6f9sR2zofDfbNMRb/nL3H7LenS6JBCzgxZ6i7muDRqs7XKnPfKRMLhBn7t
         Ry5UN2PPzpXHFm1JmHyE8Urtuf/DutRp7T617QIEzdEOCsgzp4QJCultw+nooEPixNgO
         PA8sIm/74wOnRtcIu+z6jVgHF5awTFvn8TTczRF3T6uPHEzeriWrytgi8MAAqP7sKdnQ
         A37/om10eTCdXm+my/xzZ7USbtd5n78zeP3vZhj16aSxY6EWdiyi88IQuskrLOUszdpH
         ps4A==
X-Gm-Message-State: ALoCoQmbq1j3ALjP5hqMnVtzdWbAkdswR8iOaCV17S2XW7nIJYkhv+DZtDJUl0ud2IeNcrq50+ka
X-Received: by 10.50.12.68 with SMTP id w4mr26062391igb.0.1388376462313;
        Sun, 29 Dec 2013 20:07:42 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.85.162 with SMTP id i2ls3438595qez.39.gmail; Sun, 29 Dec
 2013 20:07:41 -0800 (PST)
X-Received: by 10.224.0.139 with SMTP id 11mr28677147qab.50.1388376461782;
        Sun, 29 Dec 2013 20:07:41 -0800 (PST)
Original-Received: from mail-qe0-x232.google.com (mail-qe0-x232.google.com [2607:f8b0:400d:c02::232])
        by mx.google.com with ESMTPS id w4si369921qaj.22.2013.12.29.20.07.41
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sun, 29 Dec 2013 20:07:41 -0800 (PST)
Received-SPF: pass (google.com: domain of jyasskin@google.com designates 2607:f8b0:400d:c02::232 as permitted sender) client-ip=2607:f8b0:400d:c02::232;
Original-Received: by mail-qe0-f50.google.com with SMTP id 1so10927936qec.37
        for <std-proposals@isocpp.org>; Sun, 29 Dec 2013 20:07:41 -0800 (PST)
X-Received: by 10.49.27.8 with SMTP id p8mr106681484qeg.64.1388376461565; Sun,
 29 Dec 2013 20:07:41 -0800 (PST)
Original-Received: by 10.229.208.138 with HTTP; Sun, 29 Dec 2013 20:07:21 -0800 (PST)
In-Reply-To: <CAPOJ94NDUpX3nF+yPJeDYUZ+27RYA20NcTbbpELdrk_jcUXwpA@mail.gmail.com>
X-Original-Sender: jyasskin@google.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of jyasskin@google.com designates 2607:f8b0:400d:c02::232 as permitted
 sender) smtp.mail=jyasskin@google.com;       dkim=pass header.i=@google.com;
       dmarc=pass (p=REJECT dis=NONE) header.from=google.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:8287
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8287>

On Sun, Dec 29, 2013 at 10:15 AM, Peter Bigot <bigotp@acm.org> wrote:
> On Sun, Dec 29, 2013 at 11:35 AM, Marshall Clow <mclow.lists@gmail.com>
> wrote:
>>
>>
>> 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 th=
at 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, whi=
ch
>> 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 und=
efined
>> 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 wor=
th
> keeping in mind (libstdc++ missed that one).
>
>>
>>
>> Also, I can=92t find anywhere in the specification does it guarantee tha=
t
>> 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 t=
o
> 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.

Yeah, because this all makes sv1 equivalent to string_view(foo, 0),
and that guarantees that data()=3D=3Dfoo, the assert()s have to pass.
Hopefully the new version at
https://github.com/google/cxx-std-draft/blob/string-ref-paper/string_view.h=
tml,
which describes things in terms of exposition-only data_ and size_
members, makes this clearer.

Jeffrey

--=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/.

.
