220 28303 <4630771e-c4d2-41f2-b133-d4272c37bb81@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: keyword to make a class function unique per object
Date: Tue, 20 Sep 2016 21:02:35 -0700 (PDT)
Lines: 131
Approved: news@gmane.org
Message-ID: <4630771e-c4d2-41f2-b133-d4272c37bb81@isocpp.org>
References: <746c9278-4fcc-4022-b377-8a77e1afd043@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1464_488597594.1474430555616"
X-Trace: blaine.gmane.org 1474430571 13751 195.159.176.226 (21 Sep 2016 04:02:51 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 21 Sep 2016 04:02:51 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBXEMRC7QKGQEWT5YVZQ@isocpp.org Wed Sep 21 06:02:47 2016
Return-path: <std-proposals+bncBCEKFTV6ZUMBBXEMRC7QKGQEWT5YVZQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qt0-f200.google.com ([209.85.216.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBXEMRC7QKGQEWT5YVZQ@isocpp.org>)
	id 1bmYk3-00023b-1p
	for gclcip-std-proposals@m.gmane.org; Wed, 21 Sep 2016 06:02:39 +0200
Original-Received: by mail-qt0-f200.google.com with SMTP id p53sf75968774qtp.0
        for <gclcip-std-proposals@m.gmane.org>; Tue, 20 Sep 2016 21:02:41 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=wLAWtpBDzJyaP9qST4mGkfjZcWdQhOJJXa2xpxK60Nw=;
        b=gp20jvqTqS9mvqFzLQDvbMT2SscqTE30Zst7WONxo+OjFFc9ifaDq95ZdoppEOumvW
         jh3pudi/GXgTMvJ6hMFRESv4ldv8P8QpNXvFF+Jlm5hDUIQxRodcLNcdI1HGaBe+FSsz
         ySW4Rh5a3KymYiJK2MThedllf570ND42b0wNdGJZC+6U248I5Pzla5OJgmCxx5E4Et6N
         qdRoQbm9z44IiYKWFIfqLTYYPv9ZF4N94z+y3RDsfIy3fFV3S2YuA+SP/Qg0o+CbjMqn
         BA/wcChTVL1StzFTEjCByI3EC5sFcIr5r2MgbVnMxd4zePyX0i2sBWzMFosxYpPRcDx3
         8Bhg==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=wLAWtpBDzJyaP9qST4mGkfjZcWdQhOJJXa2xpxK60Nw=;
        b=VL7gk/g2YIGkySwqL1H0w8lxqn9xtMeqJj8m1TO3591a0KUutTG1n1Pfuy5y2K2QGS
         HaTulgy9bDMp3VbAuxbpRskicuB9HmHUp3EjFJxaKcdqcYrY5fDszkKNTiG4sIERWWZe
         4TnA5yjWezr6BQ2DQsA4t04DtZT/Or+neEtqXcQSf5EJeQqIeoBjoH3te64hS6pJusEg
         NwowOjEkQoFwQYDRFRQUp4yFKDJX3zghuJDE9EC9R5FfzUvhn1YIpYQGQlw8rHuOm9SA
         jt8gfl4MFbKd1pkiBxI+QNZcfMwob+fySS7xquLhwYoU8hph7cl6A2dAznn151/AR59I
         pjNg==
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:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=wLAWtpBDzJyaP9qST4mGkfjZcWdQhOJJXa2xpxK60Nw=;
        b=nDGee6PN8szbhlf1x9mCY2dsrt/MBbPxubblj+3/65mFxEjKmHQrXK0fviiu9zEfpR
         XzT1vaXBMWrIgJHZma/6agMvYQLogyn2Rm0LXLyoBogIN+IcMqLMLXFwR/rBUv5TcDhN
         dSArLVwBPa/leLNHVr8I5Cb69EqPajwxXxsqdz1N4nRZG18OIC3O2z0Uq3+spFzqq1OR
         fRALp94NCUeNCU8T1NXrTfZGp4poFBrnuYiCg+//KmTxU7kgtxa5w0kYMxCNcaC946p7
         yOGwMDuJOtEdDBZFWdbvEozBAUh8vT2kzCu1gNU/aSoJCl7gOa8Vfqvc2e5/uhXwiInn
         kE/Q==
X-Gm-Message-State: AE9vXwPq96tv/8bixpwmkAkKW8OFbyqCJ9B3d4IPF7AssZs7wLEFX0RfU8l5rykjb8Qe4w==
X-Received: by 10.237.34.194 with SMTP id q2mr17193430qtc.3.1474430560485;
        Tue, 20 Sep 2016 21:02:40 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.153.9 with SMTP id b9ls4297186ioe.23.gmail; Tue, 20 Sep
 2016 21:02:36 -0700 (PDT)
X-Received: by 10.36.111.147 with SMTP id x141mr75369itb.6.1474430556562;
        Tue, 20 Sep 2016 21:02:36 -0700 (PDT)
In-Reply-To: <746c9278-4fcc-4022-b377-8a77e1afd043@isocpp.org>
X-Original-Sender: jmckesson@gmail.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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://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>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:28303
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/28303>

------=_Part_1464_488597594.1474430555616
Content-Type: multipart/alternative; 
	boundary="----=_Part_1465_1368959221.1474430555617"

------=_Part_1465_1368959221.1474430555617
Content-Type: text/plain; charset=UTF-8

On Tuesday, September 20, 2016 at 6:16:23 PM UTC-4, Przemyslaw Szuplak 
wrote:
>
> Hello,
>
> I would like to have a keyword which would make a method unique (points to 
> different memory area) for an instance of class. 
>
> What is the point? Please let me explain using below example.
>
>
>
>
>
>
>
>
>
>
>
>
>
> *class CA{   template<int no>   int Get()   {          static int val = 
> foo(no);      return val;           }};//...obj1->Get<4>();obj2->Get<4>();*
>
> Currently *Get<4>()*  would return the same value for 2 different objects 
> (*obj1 *and *obj2*), because *Get()* points to the same memory area.
> There is a possibility that "foo()" may return different value depends on 
> the objects members.
>
> Basically *foo()* makes a lot of calculations depends on *no* and data 
> loaded in objects constructor. That data will not change, so i may expect 
> that *Get<4>() *will return the same value each time without repeating 
> calculations.
>

So I want to get this straight.

You have a constexpr value. And you're going to do some computation on it 
which is based on the runtime state of an object. And you want to cache 
this value. So... why not actually *do that*? There are ways to cache 
values based on an object.

Furthermore, such a cache would (presumably) be global. And therefore, if 
you happen to create two separate `CA` instances which happen to have the 
same data, you'll still get the cached value. The "keyword" idea you're 
talking about would recalculate the value in that case, since they are two 
separate instances.

Plus, by using an explicit cache, you don't have to restrict yourself to 
immutable data. That is, your way *only* works if the dependent state never 
changes. With a real cache, it would work in cases other than yours.

Why make this a language feature?

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4630771e-c4d2-41f2-b133-d4272c37bb81%40isocpp.org.

------=_Part_1465_1368959221.1474430555617
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tuesday, September 20, 2016 at 6:16:23 PM UTC-4, Przemy=
slaw Szuplak wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr">Hello,<br><br>I would like to have a keyword which would make a metho=
d unique (points to different memory area) for an instance of class. <br><b=
r>What is the point? Please let me explain using below example.<br><br><b><=
span style=3D"color:rgb(11,83,148)"><span style=3D"font-family:courier new,=
monospace">class CA<br>{<br>=C2=A0=C2=A0 template&lt;int no&gt;<br>=C2=A0=
=C2=A0 int Get()<br>=C2=A0=C2=A0 {=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 static int val =3D foo(no);<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
return val;=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0 }<br>};<b=
r><br>//...<br>obj1-&gt;Get&lt;4&gt;();<br>obj2-&gt;Get&lt;4&gt;();</span><=
/span></b><br><br>Currently <b><span style=3D"color:rgb(11,83,148)">Get&lt;=
4&gt;()</span></b>=C2=A0 would return the same value for 2 different object=
s (<b><span style=3D"color:rgb(11,83,148)">obj1 </span></b>and <b><span sty=
le=3D"color:rgb(11,83,148)">obj2</span></b>), because <span style=3D"color:=
rgb(11,83,148)"><b>Get()</b></span> points to the same memory area.<br>Ther=
e is a possibility that &quot;foo()&quot; may return different value depend=
s on the objects members.<br><br><span style=3D"color:rgb(11,83,148)"><span=
 style=3D"color:rgb(0,0,0)">Basically </span><i><b>foo()</b></i></span> mak=
es a lot of calculations depends on <i><b><span style=3D"color:rgb(11,83,14=
8)">no</span></b></i> and data loaded in objects constructor. That data wil=
l not change, so i may expect that <b><span style=3D"color:rgb(11,83,148)">=
<i>Get&lt;4&gt;()</i> </span></b><span style=3D"color:rgb(11,83,148)"><font=
 color=3D"#000000">will return the same value each time without repeating c=
alculations.</font></span></div></blockquote><div><br>So I want to get this=
 straight.<br><br>You have a constexpr value. And you&#39;re going to do so=
me computation on it which is based on the runtime state of an object. And =
you want to cache this value. So... why not actually <i>do that</i>? There =
are ways to cache values based on an object.<br><br>Furthermore, such a cac=
he would (presumably) be global. And therefore, if you happen to create two=
 separate `CA` instances which happen to have the same data, you&#39;ll sti=
ll get the cached value. The &quot;keyword&quot; idea you&#39;re talking ab=
out would recalculate the value in that case, since they are two separate i=
nstances.<br><br>Plus, by using an explicit cache, you don&#39;t have to re=
strict yourself to immutable data. That is, your way <i>only</i> works if t=
he dependent state never changes. With a real cache, it would work in cases=
 other than yours.<br><br>Why make this a language feature?</div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/4630771e-c4d2-41f2-b133-d4272c37bb81%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4630771e-c4d2-41f2-b133-d4272c37bb81=
%40isocpp.org</a>.<br />

------=_Part_1465_1368959221.1474430555617--

------=_Part_1464_488597594.1474430555616--

.
