220 8697 <20140119192238.GA19497@faust.lysator.liu.se> article
Path: news.gmane.org!not-for-mail
From: Magnus Fromreide <magfr@lysator.liu.se>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: string_view::is_null()
Date: Sun, 19 Jan 2014 20:22:40 +0100
Lines: 52
Approved: news@gmane.org
Message-ID: <20140119192238.GA19497@faust.lysator.liu.se>
References: <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>
 <52D9E336.1060801@knejp.de>
 <1B534FD7-B385-4A7E-A718-3C73F0AB61DC@gmail.com>
 <11f13f8f-1270-427c-8942-94027a181ff4@isocpp.org>
 <20140119174431.GA16875@faust.lysator.liu.se>
 <CAPOJ94Nt8tinr8hGeR-=rWZS0a529kY38NU-yo6BYM6kVo7czg@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: ger.gmane.org 1390159356 26675 80.91.229.3 (19 Jan 2014 19:22:36 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 19 Jan 2014 19:22:36 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDELLREETMBRBAWM6CLAKGQEVOHKPIY@isocpp.org Sun Jan 19 20:22:43 2014
Return-path: <std-proposals+bncBDELLREETMBRBAWM6CLAKGQEVOHKPIY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-we0-f198.google.com ([74.125.82.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDELLREETMBRBAWM6CLAKGQEVOHKPIY@isocpp.org>)
	id 1W4xxD-0001G1-5t
	for gclcip-std-proposals@m.gmane.org; Sun, 19 Jan 2014 20:22:43 +0100
Original-Received: by mail-we0-f198.google.com with SMTP id p61sf10599903wes.9
        for <gclcip-std-proposals@m.gmane.org>; Sun, 19 Jan 2014 11:22:42 -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:subject:message-id:mail-followup-to
         :references:mime-version:in-reply-to:user-agent: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-disposition;
        bh=E6Mv2FZP2nKhP8pyUMA94WbAzD2RJhfJBYyi0Ry7Rqw=;
        b=lRCJZ00m7KNCUH4ESzLqoYdk5x+TmFBxbyVT2gc0AzmAbHV1OXqYMoNCTPgsJ4H5Oz
         K+qvoRO7nFT87iIRIGwoJxnBrMZmgkKuY6x3Qr1NywtCrjedwYk2amHKeK9yrTt3DKZC
         jUHjixu2x58+MuP7uEy6msGfoc9tJGClQq1cMSaZCC/Lk5I2gGz3x0kQh+sulYGKw2KW
         icoLeLeFAO8/gyz2B7WPYOsdLAa8Lj98qVLxrik1dmTDjatNYI6Gv5VzhLtueuvYGmeg
         uCsBXijLViepD/FDpxBtLRkA9XLdmkS+OnI6IWWwamQTQRca/Uv9/jpzQWKHPbCxXkMG
  
X-Gm-Message-State: ALoCoQkJm7mmOUdWny9V1D7oqDn3ucC2bKZsr9XfojTI9McvtEPoiIv84k+9mc2QyEPmodGRQ94z
X-Received: by 10.205.34.71 with SMTP id sr7mr3223256bkb.4.1390159362646;
        Sun, 19 Jan 2014 11:22:42 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.82.227 with SMTP id l3ls382500wiy.11.canary; Sun, 19 Jan
 2014 11:22:41 -0800 (PST)
X-Received: by 10.204.235.9 with SMTP id ke9mr3658170bkb.9.1390159361861;
        Sun, 19 Jan 2014 11:22:41 -0800 (PST)
Original-Received: from mail.lysator.liu.se (mail.lysator.liu.se. [2001:6b0:17:f0a0::3])
        by mx.google.com with ESMTPS id kb4si13182651bkb.43.2014.01.19.11.22.41
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=RC4-SHA bits=128/128);
        Sun, 19 Jan 2014 11:22:41 -0800 (PST)
Received-SPF: pass (google.com: domain of magfr@lysator.liu.se designates 2001:6b0:17:f0a0::3 as permitted sender) client-ip=2001:6b0:17:f0a0::3;
Original-Received: from mail.lysator.liu.se (localhost [127.0.0.1])
	by mail.lysator.liu.se (Postfix) with ESMTP id 3004940026
	for <std-proposals@isocpp.org>; Sun, 19 Jan 2014 20:22:41 +0100 (CET)
Original-Received: from faust.lysator.liu.se (faust.lysator.liu.se [IPv6:2001:6b0:17:f0a0::d3])
	by mail.lysator.liu.se (Postfix) with SMTP id 2476F4001F
	for <std-proposals@isocpp.org>; Sun, 19 Jan 2014 20:22:40 +0100 (CET)
Original-Received: by faust.lysator.liu.se (sSMTP sendmail emulation); Sun, 19 Jan 2014 20:22:40 +0100
Mail-Followup-To: std-proposals@isocpp.org
In-Reply-To: <CAPOJ94Nt8tinr8hGeR-=rWZS0a529kY38NU-yo6BYM6kVo7czg@mail.gmail.com>
User-Agent: Mutt/1.5.20 (2009-06-14)
X-Virus-Scanned: ClamAV using ClamSMTP
X-Original-Sender: magfr@lysator.liu.se
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of magfr@lysator.liu.se designates 2001:6b0:17:f0a0::3 as permitted
 sender) smtp.mail=magfr@lysator.liu.se
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>
Content-Disposition: inline
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:8697
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8697>

On Sun, Jan 19, 2014 at 12:31:19PM -0600, Peter Bigot wrote:
> On Sun, Jan 19, 2014 at 11:44 AM, Magnus Fromreide <magfr@lysator.liu.se>wrote:
> 
> > On Sun, Jan 19, 2014 at 07:55:32AM -0800, Peter Bigot wrote:
> > > On Friday, January 17, 2014 10:19:07 PM UTC-6, Marshall wrote:
> > > >
> >
> > I have thought in a similar direction, but the problem is if you have two
> > string_view's, s1 and s2. Assume that s1 i empty, does the statement
> > s2 = s1; imply that s2.data() == s1.data()?
> >
> > Then what happens if s1 is deallocated and it's memory is returned to the
> > system, won't s2.m_ptr then hold an illegal pointer value, one of those
> > where even loading it could trigger a hardware trap on some architectures.
> >
> 
> In my approach I detect in the assignment operator and copy constructor
> whether the RHS is default-constructed, and if so invoke clear() on the
> LHS/new instance.  So in all cases either the reference is to a sequence
> outside the instance, or it's an empty default-constructed (cleared)
> instance where data() is a non-dereferenceable pointer to an internal charT
> object: no cross-object pointers.
> 
> Now that you point it out, this does result in behavior non-conformant with
> the current draft specification for the copy constructor and operator=
> which are specified as =default.
> 
> On further reflection it'd better to store a null pointer in m_ptr to
> represent a default-constructed value but to return &m_nul from data() when
> m_ptr is null.  Then the default implementations are retained.  This still
> means that data() will be always be non-null, but sv1.data() will not
> compare equal to sv2.data() if one or both of the instances have been
> cleared/default-constructed.  (sv1 == sv2 will still hold, of course.)
> 
> Does that address the objection?

The check at copy time seems to solve the problem.

The use of null as a flag value seems to interfere with the "allow null
string_views" and "have an optimized optional<string_view>" proposals
as both allow null's for other purposes.

/MF

-- 

--- 
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 email 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-proposals/.

.
