220 15962 <56a7727d-9839-45c9-be72-a6ecb61f38c9@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: mobiphil <mobi@mobiphil.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: const T* operator->() const
Date: Mon, 2 Feb 2015 06:27:24 -0800 (PST)
Lines: 154
Approved: news@gmane.org
Message-ID: <56a7727d-9839-45c9-be72-a6ecb61f38c9@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_3715_1369852134.1422887244175"
X-Trace: ger.gmane.org 1422887247 27477 80.91.229.3 (2 Feb 2015 14:27:27 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 2 Feb 2015 14:27:27 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDF3H34L74HRBTESX2TAKGQEWTGXUMI@isocpp.org Mon Feb 02 15:27:27 2015
Return-path: <std-proposals+bncBDF3H34L74HRBTESX2TAKGQEWTGXUMI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ie0-f198.google.com ([209.85.223.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDF3H34L74HRBTESX2TAKGQEWTGXUMI@isocpp.org>)
	id 1YIHyI-0001jG-Ur
	for gclcip-std-proposals@m.gmane.org; Mon, 02 Feb 2015 15:27:27 +0100
Original-Received: by mail-ie0-f198.google.com with SMTP id vy18sf117777660iec.1
        for <gclcip-std-proposals@m.gmane.org>; Mon, 02 Feb 2015 06:27: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:subject:mime-version
         :content-type:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=StuZla36D6pXcQzZi+rc2XTsfn51oQNMBcLOsaNJWQQ=;
        b=U1WoJ8V/PTVHkOQ5gfQmrxJ3lbZhPcq1c9k9ez2+51UBD/iuRx0vbMiSWcgCq9be7/
         yL3MLZwiuhzMvYR/6UM3qR5zUY0Y4ulUFYY9fQUqwhWGCRD1dY/WRYITA4IsDQYxTDN/
         gLNgGWw1n6rDm4cS27UtDDgwMd3rUr60jgEuPWXeXYgwmOwlmnMwaLjY3TYVLmC9/GF5
         B0Mt84YXH7QMvqEXhkZ315xzUlkz8uLAFaNfjOv5O5kNQDw7y9wJcwO7rNEDaTSgXfAd
         P4VITTWcQ21AUAzJHkmjm714bfjmGRT9QBzKuhi4HpjxT4BL8Chkoo2ir3YwbVdc0WtM
         IZtg==
X-Gm-Message-State: ALoCoQmccFbJGanUv3qJpWpu4Dwdc0G/jtwCEk8HtCSqSlcLhnasoNGW+chMPtlWXZPx97RBYRbn
X-Received: by 10.43.83.196 with SMTP id ah4mr17284097icc.25.1422887245226;
        Mon, 02 Feb 2015 06:27:25 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.22.163 with SMTP id 32ls2792450qgn.48.gmail; Mon, 02 Feb
 2015 06:27:24 -0800 (PST)
X-Received: by 10.140.100.163 with SMTP id s32mr60769qge.41.1422887244513;
        Mon, 02 Feb 2015 06:27:24 -0800 (PST)
X-Original-Sender: mobi@mobiphil.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: <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:15962
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/15962>

------=_Part_3715_1369852134.1422887244175
Content-Type: multipart/alternative; 
	boundary="----=_Part_3716_2080120298.1422887244175"

------=_Part_3716_2080120298.1422887244175
Content-Type: text/plain; charset=UTF-8

*Problem*: compiler does not paste const operator -> when used to refer to 
a const method
*Proposal: *well, fix it

*Context*: Thought a trivial solution for cow, but does not work. The idea 
was to have a Cow wrapper template around the classes used in my system. 
The protocol would be: if a non const method is called on the object then a 
copy is made (if necessary), otherwise just call the method. The idea was 
to play with pair of const and nonconst operator->

So, in the example below, I thought for a moment that when writing 
a->constFunc() for non const object the const "->" operator would be chosen 
by the compiler as constFunc() is const, but had to conclude that it is not 
the case.

What is your opinion? Was my expectation completely wrong. If was not 
wrong, could this make subject of a proposal?

thanks for your feedback

#include <cstdio>

template<class T>
class Cow {
   private:
      T* ptr;
   public:

      T* operator->() {
         printf("-> called\n")  ;
      }
      const T* operator->() const {
         printf("const -> called\n")  ;
      }
};

class A {
   public:
      void func() {};
      void constFunc() const  {};
};


int main()
{
   Cow<A> a = Cow<A>();
   a->constFunc(); /* as constFunc is const, would expect the operator-> 
const to be used*/

   const Cow<A> ca = Cow<A>();
   ca->constFunc(); /* well, this one uses the const operator -> */
}






-- 

--- 
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/.

------=_Part_3716_2080120298.1422887244175
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><b>Problem</b>: compiler does not paste const operato=
r -&gt; when used to refer to a const method</div><div><b>Proposal: </b>wel=
l, fix it</div><div><br></div><div><b>Context</b>: Thought a trivial soluti=
on for cow, but does not work. The idea was to have a Cow wrapper template =
around the classes used in my system. The protocol would be: if a non const=
 method is called on the object then a copy is made (if necessary), otherwi=
se just call the method. The idea was to play with pair of const and noncon=
st operator-&gt;</div><div><br></div><div>So, in the example below, I thoug=
ht for a moment that when writing a-&gt;constFunc() for non const object th=
e const "-&gt;" operator would be chosen by the compiler as constFunc() is =
const, but had to conclude that it is not the case.<br><br>What is your opi=
nion? Was my expectation completely wrong. If was not wrong, could this mak=
e subject of a proposal?<br><br></div><div>thanks for your feedback</div><d=
iv><br></div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb=
(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250, 250=
);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><div class=3D=
"subprettyprint"><font color=3D"#000000">#include &lt;cstdio&gt;</font></di=
v><div class=3D"subprettyprint"><font color=3D"#000000"><br></font></div><d=
iv class=3D"subprettyprint"><font color=3D"#000000">template&lt;class T&gt;=
</font></div><div class=3D"subprettyprint"><font color=3D"#000000">class Co=
w {</font></div><div class=3D"subprettyprint"><font color=3D"#000000">&nbsp=
; &nbsp;private:</font></div><div class=3D"subprettyprint"><font color=3D"#=
000000">&nbsp; &nbsp; &nbsp; T* ptr;</font></div><div class=3D"subprettypri=
nt"><font color=3D"#000000">&nbsp; &nbsp;public:</font></div><div class=3D"=
subprettyprint"><font color=3D"#000000"><br></font></div><div class=3D"subp=
rettyprint"><font color=3D"#000000">&nbsp; &nbsp; &nbsp; T* operator-&gt;()=
 {</font></div><div class=3D"subprettyprint"><font color=3D"#000000">&nbsp;=
 &nbsp; &nbsp; &nbsp; &nbsp;printf("-&gt; called\n") &nbsp;;</font></div><d=
iv class=3D"subprettyprint"><font color=3D"#000000">&nbsp; &nbsp; &nbsp; }<=
/font></div><div class=3D"subprettyprint"><font color=3D"#000000">&nbsp; &n=
bsp; &nbsp; const T* operator-&gt;() const {</font></div><div class=3D"subp=
rettyprint"><font color=3D"#000000">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print=
f("const -&gt; called\n") &nbsp;;</font></div><div class=3D"subprettyprint"=
><font color=3D"#000000">&nbsp; &nbsp; &nbsp; }</font></div><div class=3D"s=
ubprettyprint"><font color=3D"#000000">};</font></div><div class=3D"subpret=
typrint"><font color=3D"#000000"><br></font></div><div class=3D"subprettypr=
int"><font color=3D"#000000">class A {</font></div><div class=3D"subprettyp=
rint"><font color=3D"#000000">&nbsp; &nbsp;public:</font></div><div class=
=3D"subprettyprint"><font color=3D"#000000">&nbsp; &nbsp; &nbsp; void func(=
) {};</font></div><div class=3D"subprettyprint"><font color=3D"#000000">&nb=
sp; &nbsp; &nbsp; void constFunc() const &nbsp;{};</font></div><div class=
=3D"subprettyprint"><font color=3D"#000000">};</font></div><div class=3D"su=
bprettyprint"><font color=3D"#000000"><br></font></div><div class=3D"subpre=
ttyprint"><font color=3D"#000000"><br></font></div><div class=3D"subprettyp=
rint"><font color=3D"#000000">int main()</font></div><div class=3D"subprett=
yprint"><font color=3D"#000000">{</font></div><div class=3D"subprettyprint"=
><font color=3D"#000000">&nbsp; &nbsp;Cow&lt;A&gt; a =3D Cow&lt;A&gt;();</f=
ont></div><div class=3D"subprettyprint"><font color=3D"#000000">&nbsp; &nbs=
p;a-&gt;constFunc(); /* as constFunc is const, would expect the operator-&g=
t; const to be used*/</font></div><div class=3D"subprettyprint"><font color=
=3D"#000000"><br></font></div><div class=3D"subprettyprint"><font color=3D"=
#000000">&nbsp; &nbsp;const Cow&lt;A&gt; ca =3D Cow&lt;A&gt;();</font></div=
><div class=3D"subprettyprint"><font color=3D"#000000">&nbsp; &nbsp;ca-&gt;=
constFunc(); /* well, this one uses the const operator -&gt; */</font></div=
><div class=3D"subprettyprint"><font color=3D"#000000">}</font></div><div s=
tyle=3D"color: rgb(0, 0, 0);"><br></div><br><br><br></div></code></div><br>=
<br></div></div>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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_3716_2080120298.1422887244175--
------=_Part_3715_1369852134.1422887244175--

.
