Topic: keyword to make a class function unique per object
Author: Przemyslaw Szuplak <szuplak@gmail.com>
Date: Tue, 20 Sep 2016 15:16:23 -0700 (PDT)
Raw View
------=_Part_1044_1703710911.1474409783285
Content-Type: multipart/alternative;
boundary="----=_Part_1045_1738849787.1474409783285"
------=_Part_1045_1738849787.1474409783285
Content-Type: text/plain; charset=UTF-8
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.
The point is to make a sort of container (key-value) which would allow to
find a value in trully O(1) time. I did somethig like that - it is ultra
fast, however, it works correctly only if there is one object...
regards,
Przemyslaw Szuplak
--
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/746c9278-4fcc-4022-b377-8a77e1afd043%40isocpp.org.
------=_Part_1045_1738849787.1474409783285
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hello,<br><br>I would like to have a keyword which would m=
ake a method unique (points to different memory area) for an instance of cl=
ass. <br><br>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-fami=
ly: courier new,monospace;">class CA<br>{<br>=C2=A0=C2=A0 template<int n=
o><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>};<br><br>//...<br>obj1->Get<4>();<br>obj2->Get<=
4>();</span></span></b><br><br>Currently <b><span style=3D"color: rgb(11=
, 83, 148);">Get<4>()</span></b>=C2=A0 would return the same value fo=
r 2 different objects (<b><span style=3D"color: rgb(11, 83, 148);">obj1 </s=
pan></b>and <b><span style=3D"color: rgb(11, 83, 148);">obj2</span></b>), b=
ecause <span style=3D"color: rgb(11, 83, 148);"><b>Get()</b></span> points =
to the same memory area.<br>There is a possibility that "foo()" m=
ay return different value depends on the objects members.<br><br><span styl=
e=3D"color: rgb(11, 83, 148);"><span style=3D"color: rgb(0, 0, 0);">Basical=
ly </span><i><b>foo()</b></i></span> makes a lot of calculations depends on=
<i><b><span style=3D"color: rgb(11, 83, 148);">no</span></b></i> and data =
loaded in objects constructor. That data will not change, so i may expect t=
hat <b><span style=3D"color: rgb(11, 83, 148);"><i>Get<4>()</i> </spa=
n></b><span style=3D"color: rgb(11, 83, 148);"><font color=3D"#000000">will=
return the same value each time without repeating calculations.</font></sp=
an><br><br><br>The point is to make a sort of container (key-value) which w=
ould allow to find a value in trully O(1) time. I did somethig like that - =
it is ultra fast, however, it works correctly only if there is one object..=
..<br><br><br>regards,<br>Przemyslaw Szuplak<br><br><br><br><br><br><br><br>=
<br><br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/746c9278-4fcc-4022-b377-8a77e1afd043%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/746c9278-4fcc-4022-b377-8a77e1afd043=
%40isocpp.org</a>.<br />
------=_Part_1045_1738849787.1474409783285--
------=_Part_1044_1703710911.1474409783285--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 20 Sep 2016 21:02:35 -0700 (PDT)
Raw View
------=_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<int no><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->Get<4>();<br>obj2->Get<4>();</span><=
/span></b><br><br>Currently <b><span style=3D"color:rgb(11,83,148)">Get<=
4>()</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 "foo()" 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<4>()</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'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'll sti=
ll get the cached value. The "keyword" idea you'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'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" 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--
.