220 16068 <mb2u9u$q8c$1@ger.gmane.org> article
Path: news.gmane.org!not-for-mail
From: Matthew Woehlke <mw_triad@users.sourceforge.net>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: const T* operator->() const
Date: Fri, 06 Feb 2015 12:40:13 -0500
Lines: 61
Approved: news@gmane.org
Message-ID: <mb2u9u$q8c$1@ger.gmane.org>
References: <56a7727d-9839-45c9-be72-a6ecb61f38c9@isocpp.org> <1932997.CYfMEhPeyI@tjmaciei-mobl4> <CAGMoNKtjXtq57fxF2sxrsPXLx7Po-xfXLQQRMAhE8EeU-2+CvQ@mail.gmail.com> <1696280.25OUg0jlQd@tjmaciei-mobl4>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: ger.gmane.org 1423244432 27173 80.91.229.3 (6 Feb 2015 17:40:32 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 6 Feb 2015 17:40:32 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCO5FYHBU4ERBDXZ2OTAKGQEQVHCWLA@isocpp.org Fri Feb 06 18:40:32 2015
Return-path: <std-proposals+bncBCO5FYHBU4ERBDXZ2OTAKGQEQVHCWLA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lb0-f200.google.com ([209.85.217.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCO5FYHBU4ERBDXZ2OTAKGQEQVHCWLA@isocpp.org>)
	id 1YJmtM-0005ql-6O
	for gclcip-std-proposals@m.gmane.org; Fri, 06 Feb 2015 18:40:32 +0100
Original-Received: by mail-lb0-f200.google.com with SMTP id u14sf6892320lbd.3
        for <gclcip-std-proposals@m.gmane.org>; Fri, 06 Feb 2015 09:40:31 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:to:from:subject:date:lines:message-id:references
         :mime-version:content-type:user-agent: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;
        bh=d5RPTCnOrovECYpSImPxH4/q6gNtgz24tSZFr6SwcVg=;
        b=hbfQjmFhf1qaf9pLix8/u3su8HISJrKtEzX8gdJzZeQf5QF93/+3WX0jDsDwzDx/5N
         h56u+HRnVyaKcobgyizYdoJDD+BI6GDqrph6afpzDElGFmfNFf+U12k1hBDNZawDm6mI
         liMnd0mt1qNw1bs+nBLdm660eovXvHYHDD9hANq6d2Oc5euSUEow2cXpCRAdBgb+eycX
         DNnJEApFqmabhWoKb0AItifBpVPsd/9BVFl1k+XD9d4r4LQjJ7yM+bvNphWAnum9Dlfu
         wUo9bl8BvFeZ0Pm5/COc8rXszaCgh4mYH02poj38gSuSPRiMgkCuGnczpHtToB/9jaDP
         BrmQ==
X-Gm-Message-State: ALoCoQmdtpA+AXNlb8kki7ODPDKi5w6T9eH7nmOCNqIGmpPrHF8AJqP16froOj4JMW7+vVTwhjfC
X-Received: by 10.180.98.131 with SMTP id ei3mr433584wib.5.1423244431705;
        Fri, 06 Feb 2015 09:40:31 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.152.37.194 with SMTP id a2ls321004lak.108.gmail; Fri, 06 Feb
 2015 09:40:29 -0800 (PST)
X-Received: by 10.152.5.101 with SMTP id r5mr4125080lar.33.1423244429608;
        Fri, 06 Feb 2015 09:40:29 -0800 (PST)
Original-Received: from plane.gmane.org (plane.gmane.org. [80.91.229.3])
        by mx.google.com with ESMTPS id zl7si1849382lbb.106.2015.02.06.09.40.29
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=RC4-SHA bits=128/128);
        Fri, 06 Feb 2015 09:40:29 -0800 (PST)
Received-SPF: pass (google.com: domain of gclcip-std-proposals@m.gmane.org designates 80.91.229.3 as permitted sender) client-ip=80.91.229.3;
Original-Received: from list by plane.gmane.org with local (Exim 4.69)
	(envelope-from <gclcip-std-proposals@m.gmane.org>)
	id 1YJmtC-0005m3-QX
	for std-proposals@isocpp.org; Fri, 06 Feb 2015 18:40:23 +0100
Original-Received: from tripoint.kitware.com ([66.194.253.20])
        by main.gmane.org with esmtp (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <std-proposals@isocpp.org>; Fri, 06 Feb 2015 18:40:22 +0100
Original-Received: from mw_triad by tripoint.kitware.com with local (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <std-proposals@isocpp.org>; Fri, 06 Feb 2015 18:40:22 +0100
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 52
Original-X-Complaints-To: usenet@ger.gmane.org
X-Gmane-NNTP-Posting-Host: tripoint.kitware.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0
In-Reply-To: <1696280.25OUg0jlQd@tjmaciei-mobl4>
X-Original-Sender: mw_triad@users.sourceforge.net
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of gclcip-std-proposals@m.gmane.org designates 80.91.229.3 as
 permitted sender) smtp.mail=gclcip-std-proposals@m.gmane.org
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: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:16068
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/16068>

On 2015-02-06 11:42, Thiago Macieira wrote:
> On Friday 06 February 2015 10:50:43 mobi phil wrote:
>>> For example, the expression
>>>
>>>         type->member
>>>
>>> Is an lvalue and could be assigned to. But that doesn't mean that it is
>>> assigned to, so the operator-> would have no choice but to copy and assume
>>> that you do.
>>
>> well, if you are directly accessing members, you would compromise the
>> implementation of COW, wouldn't you?
> 
> How is accessing a member different from calling a member function? Either the 
> inner object knows it's under COW or it does.
> 
> If it does, then the operator-> is irrelevant. The member functions implement 
> the COW.

I think there may be confusion here between how QSharedDataPointer works
and how the OP's class works. The OP's class appears to be an *external*
pointer to a shared object, such that choice of whether or not to detach
happens where the *user* uses the object.

QSharedDataPointer on the other hand is a special type of PIMPL pointer.
The object held by this is never directly accessible to the user, and
from the user's perspective, COW objects are *always* copied (in Qt
terminology, they are "implicitly shared", where the "implicit" means
that the sharing/COW is normally invisible to the user).

So, for example, QString is a PIMPL class that uses QSharedDataPointer
to reference it's private data. If the user calls a const method on
QString (e.g. isEmpty()), the const operator-> is used, and no copy occurs.

So I think the confusion is because Thiago is thinking "member access"
in terms of QString accessing a member of QStringData, whereas the OP is
thinking of the application accessing a member of 'A', where 'A' is a
public class with a pointer instance being tracked by 'Cow'.

This latter approach does indeed have the sorts of issues that the OP
raises, because the determination if a detach needs to occur must be
made by the caller (i.e. the user's application) rather than the methods
of the COW object. The advantage of course is that this can be
retrofitted to any class, whereas QSharedDataPointer is an intrusive
property of the COW class. The disadvantage... is that it has the issues
that the OP raised, which is to say essentially that there is no sane
way to implement an operator-> for it currently that just Does The Right
Thing. (A work-around is to only provide data() and constData() methods,
where the former always detaches, and give up on the simplicity of '->'.)

-- 
Matthew

-- 

--- 
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/.

.
