Topic: Address of a reference: determining the value
Author: NDos Dannyu <ndospark320@naver.com>
Date: Fri, 21 Aug 2015 16:24:30 -0700 (PDT)
Raw View
------=_Part_110_1071755105.1440199470671
Content-Type: multipart/alternative;
boundary="----=_Part_111_1680266912.1440199470672"
------=_Part_111_1680266912.1440199470672
Content-Type: text/plain; charset=UTF-8
Hi.
I'm a bit confused about the exact nature of references, and I have to
determine the value category of what it refers.
For example,
* const int i(0);*
* const int &lcr(i);*
* const int &rcr(0);*
both references are valid, but lcr refers to i, but rcr refers to 0; they
are different, and they have to be distinguished.
Another example,
* #include <cstdio>*
* int main() {*
* int i(0);*
* int &r1(i);*
* int &r2(i);*
* std::printf("%p %p\n", (void *)&r1, (void *)&r2);*
* }*
this prints out two same address, which are the address of i. It makes
sense, but
* #include <cstdio>*
* int main() {*
* int i(0);*
* int &r(i);*
* const int &lcr(i);*
* const int &rcr(0);*
* int &&rr(0);*
* std::printf("%p %p %p %p\n", (void *)&r, (void *)&lcr**", (void
*)&rcr, (void *)&rr**);*
* }*
&r and &lcr prints out &i, but &rcr and &rr have their own unique value. It
doesn't make sense, as what rcr and rr refer to are what don't have an
address, they are just zeros.
So, I suggest them to be nullptrs. More precisely, in terms of built-in
operators:
*template <class T>*
* T *operator & (/* a value v */) {*
* return /* The address of v */;*
* }*
* template <class T>*
* const T *operator & (/* a const value cv */) {*
* return /* The add ress of cv */;*
* }*
* template <class T>*
* T *operator & (/* a lvalue reference r */) {*
* return /* The address of what r refers to */;*
* }*
* template <class T>*
* const T *operator & (/* a const lvalue reference cr */) {*
* if (/* cr refers to a lvalue */) /* The address of what cr refers
to */;*
* else return (const T *)nullptr;*
* }*
* template <class T>*
* T *operator & (/* a rvalue reference rr */) {*
* return (T *)nullptr;*
* }*
so the value category of what a const reference refers to can be
determined, by comparing the address of it with nullptr.
--
---
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_111_1680266912.1440199470672
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Hi.</div><div>I'm a bit confused about the exact =
nature of references, and I have to determine the value category of what it=
refers.</div><div>For example,</div><div><strong>=C2=A0=C2=A0=C2=A0 const =
int i(0);</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 const int &lcr(=
i);</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 const int &rcr(0);</s=
trong></div><div>both references are valid, but lcr refers to i, but rcr re=
fers to 0; they are different, and they have to be distinguished.</div><div=
>Another example,</div><div><strong>=C2=A0=C2=A0=C2=A0 #include <cstdio&=
gt;</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 int main() {</strong></di=
v><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int i(0);</strong=
></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int &r1(=
i);</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 i=
nt &r2(i);</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 std::printf("%p %p\n", (void *)&r1, (void *)&r2=
);</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 }</strong></div><div>this =
prints out two same address, which are the address of i.=C2=A0It makes sens=
e, but</div><div><div><strong>=C2=A0=C2=A0=C2=A0 #include <cstdio></s=
trong></div><div><strong>=C2=A0=C2=A0=C2=A0 int main() {</strong></div><div=
><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int i(0);</strong></div=
><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int &r(i);</st=
rong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const in=
t &lcr(i);</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 const int &rcr(0);</strong></div><div><strong>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 int &&rr(0);</strong></div><div><strong=
>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::printf("%p %p %p %p\n=
", (void *)&r, (void *)&lcr</strong><strong>", (void *)&a=
mp;rcr, (void *)&rr</strong><strong>);</strong></div><div><strong>=C2=
=A0=C2=A0=C2=A0 }</strong></div><div>&r and &lcr prints out &i,=
but &rcr and &rr have their own unique value. It doesn't make =
sense, as what rcr and rr refer to are what don't have an address, they=
are just zeros.</div><div>So, I suggest them to be nullptrs. More precisel=
y, in terms of built-in operators:</div><div>=C2=A0=C2=A0=C2=A0 <strong>tem=
plate <class T></strong></div><div><strong>=C2=A0=C2=A0=C2=A0 T *oper=
ator & (/* a value v */) {</strong></div><div><strong>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 return /* The address of v */;</strong></div><d=
iv><strong>=C2=A0=C2=A0=C2=A0 }</strong></div><div><strong>=C2=A0=C2=A0=C2=
=A0 template <class T></strong></div><div><strong>=C2=A0=C2=A0=C2=A0 =
const T *operator & (/* a const value cv */) {</strong></div><div><stro=
ng>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return /* The add ress of cv =
*/;</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 }</strong></div><div><str=
ong>=C2=A0=C2=A0=C2=A0 template <class T></strong></div><div><strong>=
=C2=A0=C2=A0=C2=A0 T *operator & (/* a lvalue reference r */) {</strong=
></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return /* Th=
e address of what r refers to */;</strong></div><div><strong>=C2=A0=C2=A0=
=C2=A0 }</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 template <class T=
></strong></div><div><strong>=C2=A0=C2=A0=C2=A0 const T *operator & =
(/* a const lvalue=C2=A0reference cr */) {</strong></div><div><strong>=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (/* cr refers to a lvalue */) /*=
The address of what cr refers to */;</strong></div><div><strong>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 else return (const T *)nullptr;</strong><=
/div><div><strong>=C2=A0=C2=A0=C2=A0 }</strong></div><div><strong>=C2=A0=C2=
=A0=C2=A0 template <class T></strong></div><div><strong>=C2=A0=C2=A0=
=C2=A0 T *operator & (/* a rvalue reference rr */) {</strong></div><div=
><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return (T *)nullptr;</s=
trong></div><div><strong>=C2=A0=C2=A0=C2=A0 }</strong></div><div>so the val=
ue category=C2=A0of=C2=A0what a=C2=A0const reference refers to can be deter=
mined, by comparing the address of it with nullptr.</div></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" 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_111_1680266912.1440199470672--
------=_Part_110_1071755105.1440199470671--
.
Author: "'Matt Calabrese' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Fri, 21 Aug 2015 16:49:43 -0700
Raw View
--047d7b33d9520afe29051ddaec9c
Content-Type: text/plain; charset=UTF-8
On Fri, Aug 21, 2015 at 4:24 PM, NDos Dannyu <ndospark320@naver.com> wrote:
>
> &r and &lcr prints out &i, but &rcr and &rr have their own unique value.
> It doesn't make sense, as what rcr and rr refer to are what don't have an
> address, they are just zeros.
> So, I suggest them to be nullptrs. More precisely, in terms of built-in
> operators:
>
I don't understand the purpose of this and it would break otherwise sound
code. Taking the address of an object in C++ doesn't yield a null pointer,
and users should be able to dereference the address of an object to
retrieve the original value. Similarly, different objects of the same type
have unique addresses. What you propose would break these assumption and
associated uses, and do so in a subtle way. This also wouldn't really be
implementable anyway, IIUC, since soon as you introduce a level of
indirection by passing the object by reference to a function, you'd no
longer know that it referred to a literal (what would you expect to see if
you took the address of the parameter from inside of the function).
I don't really see the purpose of this change, but whatever it is, there is
probably a more direct solution to your needs than changing the behavior of
&
--
---
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/.
--047d7b33d9520afe29051ddaec9c
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On F=
ri, Aug 21, 2015 at 4:24 PM, NDos Dannyu <span dir=3D"ltr"><<a href=3D"m=
ailto:ndospark320@naver.com" target=3D"_blank">ndospark320@naver.com</a>>=
;</span> wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex=
;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div>&a=
mp;r and &lcr prints out &i, but &rcr and &rr have their ow=
n unique value. It doesn't make sense, as what rcr and rr refer to are =
what don't have an address, they are just zeros.</div><div>So, I sugges=
t them to be nullptrs. More precisely, in terms of built-in operators:</div=
></div></div></blockquote><div><br></div><div>I don't understand the pu=
rpose of this and it would break otherwise sound code. Taking the address o=
f an object in C++ doesn't yield a null pointer, and users should be ab=
le to dereference the address of an object to retrieve the original value. =
Similarly, different objects of the same type have unique addresses. What y=
ou propose would break these assumption and associated uses, and do so in a=
subtle way. This also wouldn't really be implementable anyway, IIUC, s=
ince soon as you introduce a level of indirection by passing the object by =
reference to a function, you'd no longer know that it referred to a lit=
eral (what would you expect to see if you took the address of the parameter=
from inside of the function).</div><div><br></div><div>I don't really =
see the purpose of this change, but whatever it is, there is probably a mor=
e direct solution to your needs than changing the behavior of &</div></=
div></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" 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 />
--047d7b33d9520afe29051ddaec9c--
.
Author: NDos Dannyu <ndospark320@naver.com>
Date: Fri, 21 Aug 2015 17:52:59 -0700 (PDT)
Raw View
------=_Part_324_626021455.1440204779259
Content-Type: multipart/alternative;
boundary="----=_Part_325_475612207.1440204779259"
------=_Part_325_475612207.1440204779259
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=A4=
=EC=A0=84 8=EC=8B=9C 49=EB=B6=84 45=EC=B4=88 UTC+9, Matt Calabrese =EB=8B=
=98=EC=9D=98 =EB=A7=90:
> Taking the address of an object in C++ doesn't yield a null pointer, and=
=20
> users should be able to dereference the address of an object to retrieve=
=20
> the original value.=20
>
A reference ISN'T an object; it is, literally, a reference to an object.
But *const int &rcr(0)* doesn't refer to an object. It refers to zero,=20
which isn't an object. Zero doesn't have an address, so rcr should also not=
=20
have an address.
> This also wouldn't really be implementable anyway
I thought the compiler would know what a reference is and what the=20
reference refers to. Isn't it implementable built-in then...?
> since soon as you introduce a level of indirection by passing the object=
=20
> by reference to a function, you'd no longer know that it referred to a=20
> literal
I don't get it. For example:
*int &foor(int &r) {*
* return r;*
* }*
* const int &foocr(const int &rc) {*
* return cr;*
* }*
*int &&foorr(int &&rr) {*
* return rr;*
* }*
* int main() {*
* int i(0);*
* foor(i); // OK*
* // foor(0); // error: r can't be initialized with 0*
* foocr(i); // OK*
* foocr(0); // OK*
* // foorr(i); // error: rr can't be initialized with i*
* foorr(0); // OK*
* }*
A function every argument is initialized when it is called; the function=20
well-knows what its arguments exactly are. No problem.
My original intentions were:
I have a value class indicating a finite discrete random variable.
But I had a problem. For example, assume that I have a variable named X.
But how can P(X<X=C2=B2) interpreted? X is still X, even it is squared, isn=
't it?
Things will get much more complicated if I have multiple variables, X, Y=20
and Z,
and I have to do like P(X<X=C2=B2=3DY>|Z|) or something.=20
So I decided to make a bind of variables.
It would be a tree structure, consisting of other binds or variables.
If it consists of references of variables, it will know what variables are=
=20
same(or dependant) and what variables are different(or indepentant).
But how can I deal with rvalues? For examples, 1 can be seen as a variable=
=20
which is always 1.
But it has no name. It is just 1. It is always indepentant from=20
other variables.
So I made it to consist of const lvalue references,=20
which can initialized with lvalue or rvalue.
But how can I determine it refers to lvalue or rvalue?? I couldn't find any=
=20
solution from the standard library.=20
=20
=20
=20
=20
--=20
---=20
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 e=
mail 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-proposa=
ls/.
------=_Part_325_475612207.1440204779259
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=
=9A=94=EC=9D=BC =EC=98=A4=EC=A0=84 8=EC=8B=9C 49=EB=B6=84 45=EC=B4=88 UTC+9=
, Matt Calabrese =EB=8B=98=EC=9D=98 =EB=A7=90:<br><blockquote class=3D"gmai=
l_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left=
-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: soli=
d;"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div>Taking the addres=
s of an object in C++ doesn't yield a null pointer, and users should be=
able to dereference the address of an object to retrieve the original valu=
e. </div></div></div></div></blockquote><div>A reference ISN'T an objec=
t; it is, literally, a reference to an object.</div><div>But <strong>const =
int &rcr(0)</strong> doesn't refer to an object. It refers to zero,=
which isn't an object. Zero doesn't have an address, so rcr should=
also not have an address.</div><blockquote class=3D"gmail_quote" style=3D"=
margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 2=
04, 204); border-left-width: 1px; border-left-style: solid;">This also woul=
dn't really be implementable anyway</blockquote><div>I thought the comp=
iler would know what=C2=A0a=C2=A0reference is and what the reference refers=
to. Isn't=C2=A0it implementable built-in then...?</div><blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; b=
order-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-s=
tyle: solid;">=C2=A0since soon as you introduce a level of indirection by p=
assing the object by reference to a function, you'd no longer know that=
it referred to a literal</blockquote><div>I don't get it.=C2=A0For exa=
mple:</div><div>=C2=A0=C2=A0=C2=A0=C2=A0<strong>int=C2=A0&foor(int &=
;r) {</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
return r;</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 }</strong></div><d=
iv><strong>=C2=A0=C2=A0=C2=A0 const int &foocr(const int &rc) {</st=
rong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return c=
r;</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 }</strong></div><div>=C2=
=A0=C2=A0=C2=A0 <strong>int &&foorr(int &&rr) {</strong></d=
iv><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return rr;</stro=
ng></div><div><strong>=C2=A0=C2=A0=C2=A0 }</strong></div><div><strong>=C2=
=A0=C2=A0=C2=A0 int main() {</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 int i(0);</strong></div><div><strong>=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 foor(i); // OK</strong></div><div><strong>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // foor(0); // error: r can'=
t be initialized with 0</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 foocr(i); // OK</strong></div><div><strong>=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 foocr(0); // OK</strong></div><div><strong>=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // foorr(i); // error: rr can=
9;t be initialized with i</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 foorr(0); // OK</strong></div><div><strong>=C2=A0=C2=
=A0=C2=A0 }</strong></div><div>A function every argument is initialized whe=
n it is called; the function well-knows what its arguments exactly are. No =
problem.</div><div><br></div><div>My original intentions were:</div><blockq=
uote style=3D"margin-right: 0px;" dir=3D"ltr"><div><font color=3D"#000000">=
I have a value class indicating a finite discrete random variable.</font></=
div><div>But I had a problem. For example, assume that=C2=A0I have a variab=
le named X.</div><div>But=C2=A0how=C2=A0can=C2=A0P(X<X=C2=B2) interprete=
d? X is still X, even it is squared, isn't it?</div><div>Things will ge=
t much more complicated if=C2=A0I have multiple variables, X, Y and Z,</div=
><div>and I have to do like P(X<X=C2=B2=3DY>|Z|) or something.=C2=A0<=
/div><div>So I decided to=C2=A0make a bind of variables.</div><div>It would=
be a tree structure, consisting of=C2=A0other=C2=A0binds=C2=A0or variables=
..</div><div>If=C2=A0it=C2=A0consists=C2=A0of references of variables, it wi=
ll know what variables are same(or dependant) and=C2=A0what variables are d=
ifferent(or indepentant).</div><div>But=C2=A0how can I deal with rvalues?=
=C2=A0For examples, 1 can be seen as a variable which is always 1.</div><di=
v>But it has=C2=A0no name. It is just 1. It=C2=A0is always indepentant from=
other=C2=A0variables.</div><div>So I=C2=A0made it=C2=A0to consist of const=
lvalue references, which=C2=A0can=C2=A0initialized=C2=A0with lvalue or rva=
lue.</div><div>But=C2=A0how can I determine it=C2=A0refers to lvalue or rva=
lue?? I couldn't find any solution from the standard library.=C2=A0</di=
v></blockquote><blockquote style=3D"margin-right: 0px;" dir=3D"ltr"><div>=
=C2=A0</div><div>=C2=A0</div><div>=C2=A0</div><div>=C2=A0</div></blockquote=
><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padd=
ing-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1p=
x; border-left-style: solid;"></blockquote></div>
<p></p>
-- <br />
<br />
--- <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 />
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_325_475612207.1440204779259--
------=_Part_324_626021455.1440204779259--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Fri, 21 Aug 2015 18:14:47 -0700
Raw View
--bcaec51d225441a9de051ddc1cf0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Fri, Aug 21, 2015 at 5:52 PM, NDos Dannyu <ndospark320@naver.com> wrote:
>
>
> 2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=
=A4=EC=A0=84 8=EC=8B=9C 49=EB=B6=84 45=EC=B4=88 UTC+9, Matt Calabrese =EB=
=8B=98=EC=9D=98 =EB=A7=90:
>
>> Taking the address of an object in C++ doesn't yield a null pointer, and
>> users should be able to dereference the address of an object to retrieve
>> the original value.
>>
> A reference ISN'T an object; it is, literally, a reference to an object.
> But *const int &rcr(0)* doesn't refer to an object. It refers to zero,
> which isn't an object. Zero doesn't have an address, so rcr should also n=
ot
> have an address.
>
That's not correct. "const int &rcr(0)" implicitly creates a temporary
object of type int and binds the reference to that object. (The reference
binding then extends the lifetime of that temporary object to the lifetime
of the reference.)
> This also wouldn't really be implementable anyway
>
> I thought the compiler would know what a reference is and what the
> reference refers to. Isn't it implementable built-in then...?
>
>> since soon as you introduce a level of indirection by passing the objec=
t
>> by reference to a function, you'd no longer know that it referred to a
>> literal
>
> I don't get it. For example:
> *int &foor(int &r) {*
> * return r;*
> * }*
> * const int &foocr(const int &rc) {*
> * return cr;*
> * }*
> *int &&foorr(int &&rr) {*
> * return rr;*
> * }*
> * int main() {*
> * int i(0);*
> * foor(i); // OK*
> * // foor(0); // error: r can't be initialized with 0*
> * foocr(i); // OK*
> * foocr(0); // OK*
> * // foorr(i); // error: rr can't be initialized with i*
> * foorr(0); // OK*
> * }*
> A function every argument is initialized when it is called; the function
> well-knows what its arguments exactly are. No problem.
>
> My original intentions were:
>
> I have a value class indicating a finite discrete random variable.
> But I had a problem. For example, assume that I have a variable named X.
> But how can P(X<X=C2=B2) interpreted? X is still X, even it is squared, i=
sn't
> it?
> Things will get much more complicated if I have multiple variables, X, Y
> and Z,
> and I have to do like P(X<X=C2=B2=3DY>|Z|) or something.
> So I decided to make a bind of variables.
> It would be a tree structure, consisting of other binds or variables.
> If it consists of references of variables, it will know what variables ar=
e
> same(or dependant) and what variables are different(or indepentant).
> But how can I deal with rvalues? For examples, 1 can be seen as a variabl=
e
> which is always 1.
> But it has no name. It is just 1. It is always indepentant from
> other variables.
> So I made it to consist of const lvalue references,
> which can initialized with lvalue or rvalue.
> But how can I determine it refers to lvalue or rvalue?? I couldn't find
> any solution from the standard library.
>
>
>
>
>
>
> --
>
> ---
> 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/.
>
--=20
---=20
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 e=
mail 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-proposa=
ls/.
--bcaec51d225441a9de051ddc1cf0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On F=
ri, Aug 21, 2015 at 5:52 PM, NDos Dannyu <span dir=3D"ltr"><<a href=3D"m=
ailto:ndospark320@naver.com" target=3D"_blank">ndospark320@naver.com</a>>=
;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 =
..8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><br><br>=
2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=A4=
=EC=A0=84 8=EC=8B=9C 49=EB=B6=84 45=EC=B4=88 UTC+9, Matt Calabrese =EB=8B=
=98=EC=9D=98 =EB=A7=90:<span class=3D""><br><blockquote class=3D"gmail_quot=
e" style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb=
(204,204,204);border-left-width:1px;border-left-style:solid"><div dir=3D"lt=
r"><div><div class=3D"gmail_quote"><div>Taking the address of an object in =
C++ doesn't yield a null pointer, and users should be able to dereferen=
ce the address of an object to retrieve the original value. </div></div></d=
iv></div></blockquote></span><div>A reference ISN'T an object; it is, l=
iterally, a reference to an object.</div><div>But <strong>const int &rc=
r(0)</strong> doesn't refer to an object. It refers to zero, which isn&=
#39;t an object. Zero doesn't have an address, so rcr should also not h=
ave an address.</div></div></blockquote><div><br></div><div>That's not =
correct. "const int &rcr(0)" implicitly creates a temporary o=
bject of type int and binds the reference to that object. (The reference bi=
nding then extends the lifetime of that temporary object to the lifetime of=
the reference.)</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div =
dir=3D"ltr"><span class=3D""><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);b=
order-left-width:1px;border-left-style:solid">This also wouldn't really=
be implementable anyway</blockquote></span><div>I thought the compiler wou=
ld know what=C2=A0a=C2=A0reference is and what the reference refers to. Isn=
't=C2=A0it implementable built-in then...?</div><span class=3D""><block=
quote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;padding-left:=
1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-st=
yle:solid">=C2=A0since soon as you introduce a level of indirection by pass=
ing the object by reference to a function, you'd no longer know that it=
referred to a literal</blockquote></span><div>I don't get it.=C2=A0For=
example:</div><div>=C2=A0=C2=A0=C2=A0=C2=A0<strong>int=C2=A0&foor(int =
&r) {</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 return r;</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 }</strong></=
div><div><strong>=C2=A0=C2=A0=C2=A0 const int &foocr(const int &rc)=
{</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 re=
turn cr;</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 }</strong></div><div=
>=C2=A0=C2=A0=C2=A0 <strong>int &&foorr(int &&rr) {</strong=
></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return rr;</=
strong></div><div><strong>=C2=A0=C2=A0=C2=A0 }</strong></div><div><strong>=
=C2=A0=C2=A0=C2=A0 int main() {</strong></div><div><strong>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 int i(0);</strong></div><div><strong>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 foor(i); // OK</strong></div><div><strong=
>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // foor(0); // error: r can'=
;t be initialized with 0</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0 foocr(i); // OK</strong></div><div><strong>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 foocr(0); // OK</strong></div><div><stron=
g>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // foorr(i); // error: rr can&=
#39;t be initialized with i</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 foorr(0); // OK</strong></div><div><strong>=C2=A0=
=C2=A0=C2=A0 }</strong></div><div>A function every argument is initialized =
when it is called; the function well-knows what its arguments exactly are. =
No problem.</div><div><br></div><div>My original intentions were:</div><blo=
ckquote style=3D"margin-right:0px" dir=3D"ltr"><div><font color=3D"#000000"=
>I have a value class indicating a finite discrete random variable.</font><=
/div><div>But I had a problem. For example, assume that=C2=A0I have a varia=
ble named X.</div><div>But=C2=A0how=C2=A0can=C2=A0P(X<X=C2=B2) interpret=
ed? X is still X, even it is squared, isn't it?</div><div>Things will g=
et much more complicated if=C2=A0I have multiple variables, X, Y and Z,</di=
v><div>and I have to do like P(X<X=C2=B2=3DY>|Z|) or something.=C2=A0=
</div><div>So I decided to=C2=A0make a bind of variables.</div><div>It woul=
d be a tree structure, consisting of=C2=A0other=C2=A0binds=C2=A0or variable=
s.</div><div>If=C2=A0it=C2=A0consists=C2=A0of references of variables, it w=
ill know what variables are same(or dependant) and=C2=A0what variables are =
different(or indepentant).</div><div>But=C2=A0how can I deal with rvalues?=
=C2=A0For examples, 1 can be seen as a variable which is always 1.</div><di=
v>But it has=C2=A0no name. It is just 1. It=C2=A0is always indepentant from=
other=C2=A0variables.</div><div>So I=C2=A0made it=C2=A0to consist of const=
lvalue references, which=C2=A0can=C2=A0initialized=C2=A0with lvalue or rva=
lue.</div><div>But=C2=A0how can I determine it=C2=A0refers to lvalue or rva=
lue?? I couldn't find any solution from the standard library.=C2=A0</di=
v></blockquote><blockquote style=3D"margin-right:0px" dir=3D"ltr"><div>=C2=
=A0</div><div>=C2=A0</div><div>=C2=A0</div><div>=C2=A0</div></blockquote><b=
lockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;padding-l=
eft:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-lef=
t-style:solid"></blockquote></div><div class=3D"HOEnZb"><div class=3D"h5">
<p></p>
-- <br>
<br>
--- <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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><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" 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 />
--bcaec51d225441a9de051ddc1cf0--
.
Author: NDos Dannyu <ndospark320@naver.com>
Date: Fri, 21 Aug 2015 18:21:57 -0700 (PDT)
Raw View
------=_Part_345_1998461344.1440206517428
Content-Type: multipart/alternative;
boundary="----=_Part_346_598790373.1440206517428"
------=_Part_346_598790373.1440206517428
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=A4=
=EC=A0=84 10=EC=8B=9C 14=EB=B6=84 49=EC=B4=88 UTC+9, Richard Smith =EB=8B=
=98=EC=9D=98 =EB=A7=90:
> That's not correct. "const int &rcr(0)" implicitly creates a temporary=20
> object of type int and binds the reference to that object. (The reference=
=20
> binding then extends the lifetime of that temporary object to the lifetim=
e=20
> of the reference.)
>
I'm speaking about what it means, not how it is implemented. Even if it is=
=20
implemented as it refers to a temporary object, it should be treated as it=
=20
doesn't refer to an object, I mean.
--=20
---=20
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 e=
mail 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-proposa=
ls/.
------=_Part_346_598790373.1440206517428
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=
=9A=94=EC=9D=BC =EC=98=A4=EC=A0=84 10=EC=8B=9C 14=EB=B6=84 49=EC=B4=88 UTC+=
9, Richard Smith =EB=8B=98=EC=9D=98 =EB=A7=90:<br><blockquote class=3D"gmai=
l_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left=
-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: soli=
d;"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div>That's not co=
rrect. "const int &rcr(0)" implicitly creates a temporary obj=
ect of type int and binds the reference to that object. (The reference bind=
ing then extends the lifetime of that temporary object to the lifetime of t=
he reference.)<br></div></div></div></div></blockquote><div>=C2=A0I'm s=
peaking about what it means, not how it is implemented. Even if it is imple=
mented as it refers to a temporary object, it should be treated as it doesn=
't refer to an object, I mean.</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" 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_346_598790373.1440206517428--
------=_Part_345_1998461344.1440206517428--
.
Author: David Krauss <potswa@gmail.com>
Date: Sat, 22 Aug 2015 09:37:36 +0800
Raw View
--Apple-Mail=_582A9A05-5F6D-4BCA-821D-D4FB888C917A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
> On 2015=E2=80=9308=E2=80=9322, at 9:21 AM, NDos Dannyu <ndospark320@naver=
..com> wrote:
>=20
> 2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=
=A4=EC=A0=84 10=EC=8B=9C 14=EB=B6=84 49=EC=B4=88 UTC+9, Richard Smith =EB=
=8B=98=EC=9D=98 =EB=A7=90:
> That's not correct. "const int &rcr(0)" implicitly creates a temporary ob=
ject of type int and binds the reference to that object. (The reference bin=
ding then extends the lifetime of that temporary object to the lifetime of =
the reference.)
> I'm speaking about what it means, not how it is implemented. Even if it =
is implemented as it refers to a temporary object, it should be treated as =
it doesn't refer to an object, I mean.
It=E2=80=99s part of the meaning of the program, not an arbitrary implement=
ation detail. Excerpt from my upcoming proposal, revising N4221:
> Lifetime extension is a very old C++ feature, originating before ISO stan=
dardization began. Initializing a const& reference variable from a function=
result to avoid a copy has worked since references were introduced. =E2=80=
=A6Temporaries all worked that way at first =E2=80=A6 During the drafting o=
f the ARM (1988-1989), Stroustrup blessed the idea of early destruction of =
temporary objects. =E2=80=A6 Basic interoperability required some form of l=
ifetime extension rule.
>=20
--=20
---=20
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 e=
mail 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-proposa=
ls/.
--Apple-Mail=_582A9A05-5F6D-4BCA-821D-D4FB888C917A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9308=
=E2=80=9322, at 9:21 AM, NDos Dannyu <<a href=3D"mailto:ndospark320@nave=
r.com" class=3D"">ndospark320@naver.com</a>> wrote:</div><div class=3D""=
><div dir=3D"ltr" class=3D""><br class=3D"">2015=EB=85=84 8=EC=9B=94 22=EC=
=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=A4=EC=A0=84 10=EC=8B=9C 14=EB=B6=
=84 49=EC=B4=88 UTC+9, Richard Smith =EB=8B=98=EC=9D=98 =EB=A7=90:<br class=
=3D""><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex;=
padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-widt=
h: 1px; border-left-style: solid;"><div dir=3D"ltr" class=3D""><div class=
=3D""><div class=3D"gmail_quote"><div class=3D"">That's not correct. "const=
int &rcr(0)" implicitly creates a temporary object of type int and bin=
ds the reference to that object. (The reference binding then extends the li=
fetime of that temporary object to the lifetime of the reference.)<br class=
=3D""></div></div></div></div></blockquote><div class=3D""> I'm speaki=
ng about what it means, not how it is implemented. Even if it is implemente=
d as it refers to a temporary object, it should be treated as it doesn't re=
fer to an object, I mean.</div></div></div></blockquote><br class=3D""></di=
v><div>It=E2=80=99s part of the meaning of the program, not an arbitrary im=
plementation detail. Excerpt from my upcoming proposal, revising N4221:</di=
v><div><br class=3D""></div><div><blockquote type=3D"cite" class=3D""><p st=
yle=3D"margin: 0px 0px 6px; -webkit-text-stroke-color: rgb(0, 0, 0); -webki=
t-text-stroke-width: initial;" class=3D"">Lifetime extension is a very old =
C++ feature, originating before ISO standardization began. Initializing a <=
span style=3D"font-size: 11px; font-family: Courier; background-color: rgb(=
245, 245, 245);" class=3D"">const&</span> reference variable from a fun=
ction result to avoid a copy has worked since references were introduced. =
=E2=80=A6<span style=3D"-webkit-text-stroke-width: initial;" class=3D"">Tem=
poraries all worked that way at first </span><span style=3D"-webkit-te=
xt-stroke-width: initial;" class=3D"">=E2=80=A6 </span><span style=3D"=
-webkit-text-stroke-width: initial;" class=3D"">During the drafting of the =
ARM (1988-1989), Stroustrup blessed the idea of early destruction of tempor=
ary objects</span><span style=3D"-webkit-text-stroke-width: initial;" class=
=3D"">. =E2=80=A6 Basic interoperability required some form of lifetime ext=
ension rule.</span></p></blockquote></div><div class=3D""><br class=3D""></=
div></body></html>
<p></p>
-- <br />
<br />
--- <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 />
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 />
--Apple-Mail=_582A9A05-5F6D-4BCA-821D-D4FB888C917A--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Fri, 21 Aug 2015 19:24:47 -0700
Raw View
On Friday 21 August 2015 18:21:57 NDos Dannyu wrote:
> 2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=
=A4=EC=A0=84 10=EC=8B=9C 14=EB=B6=84 49=EC=B4=88 UTC+9, Richard Smith =EB=
=8B=98=EC=9D=98 =EB=A7=90:
> > That's not correct. "const int &rcr(0)" implicitly creates a temporary
> > object of type int and binds the reference to that object. (The referen=
ce
> > binding then extends the lifetime of that temporary object to the lifet=
ime
> > of the reference.)
>=20
> I'm speaking about what it means, not how it is implemented. Even if it =
is
> implemented as it refers to a temporary object, it should be treated as i=
t
> doesn't refer to an object, I mean.
It means what Richard said: it refers to an object which has an address. Th=
e=20
fact that it is temporary isn't relevant.
And changing this now isn't a good idea. Not to mention that it can't be=20
implemented. Take, for example:
int *doit(const int &ref)
{
printf("%d\n", ref);
return &ref;
}
You're saying that the function doit above should return null if it was cal=
led=20
with a reference to a temporary. But if it does so, how will it print the=
=20
value that was referenced?
Besides, we're missing an important aspect: why do you want this? What's th=
e=20
motivation?
--=20
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--=20
---=20
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 e=
mail 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-proposa=
ls/.
.
Author: NDos Dannyu <ndospark320@naver.com>
Date: Fri, 21 Aug 2015 19:42:13 -0700 (PDT)
Raw View
------=_Part_53_1393151064.1440211333630
Content-Type: multipart/alternative;
boundary="----=_Part_54_312722975.1440211333637"
------=_Part_54_312722975.1440211333637
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=A4=
=EC=A0=84 11=EC=8B=9C 24=EB=B6=84 55=EC=B4=88 UTC+9, Thiago Macieira =EB=8B=
=98=EC=9D=98 =EB=A7=90:
>
>
> You're saying that the function doit above should return null if it was=
=20
> called=20
> with a reference to a temporary. But if it does so, how will it print the=
=20
> value that was referenced?=20
>
Does printf need its address??=20
> Besides, we're missing an important aspect: why do you want this? What's=
=20
> the=20
> motivation?=20
>
I'm writing my story again:
I have a value class indicating a finite discrete random variable.
But I had a problem. For example, assume that I have a variable named X.
But how can P(X<X=C2=B2) interpreted? X is still X, even it is squared, isn=
't it?
Things will get much more complicated if I have multiple variables, X, Y=20
and Z,
and I have to do like P(X<X=C2=B2=3DY>|Z|) or something.=20
So I decided to make a bind of variables.
It would be a tree structure, consisting of other binds or variables.
If it consists of references of variables, it will know what variables are=
=20
same(or dependant) and what variables are different(or indepentant).
But how can I deal with rvalues? For examples, 1 can be seen as a variable=
=20
which is always 1.
But it has no name. It is just 1. It is always indepentant from=20
other variables.
So I made it to consist of const lvalue references,=20
which can initialized with lvalue or rvalue.
But how can I determine it refers to lvalue or rvalue?? I couldn't find any=
=20
solution from the standard library.
--=20
---=20
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 e=
mail 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-proposa=
ls/.
------=_Part_54_312722975.1440211333637
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=
=9A=94=EC=9D=BC =EC=98=A4=EC=A0=84 11=EC=8B=9C 24=EB=B6=84 55=EC=B4=88 UTC+=
9, Thiago Macieira =EB=8B=98=EC=9D=98 =EB=A7=90:<blockquote class=3D"gmail_=
quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-c=
olor: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;=
"><br>You're saying that the function doit above should return null if =
it was called=20
<br>with a reference to a temporary. But if it does so, how will it print t=
he=20
<br>value that was referenced?
<br></blockquote><div>Does=C2=A0printf need its address??=C2=A0</div><block=
quote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-lef=
t: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; bord=
er-left-style: solid;">Besides, we're missing an important aspect: why =
do you want this? What's the=20
<br>motivation?
<br></blockquote><div>I'm writing my story again:</div><div><blockquote=
style=3D"margin-right: 0px;" dir=3D"ltr"><div><font color=3D"#000000">I ha=
ve a value class indicating a finite discrete random variable.</font></div>=
<div>But I had a problem. For example, assume that=C2=A0I have a variable n=
amed X.</div><div>But=C2=A0how=C2=A0can=C2=A0P(X<X=C2=B2) interpreted? X=
is still X, even it is squared, isn't it?</div><div>Things will get mu=
ch more complicated if=C2=A0I have multiple variables, X, Y and Z,</div><di=
v>and I have to do like P(X<X=C2=B2=3DY>|Z|) or something.=C2=A0</div=
><div>So I decided to=C2=A0make a bind of variables.</div><div>It would be =
a tree structure, consisting of=C2=A0other=C2=A0binds=C2=A0or variables.</d=
iv><div>If=C2=A0it=C2=A0consists=C2=A0of references of variables, it will k=
now what variables are same(or dependant) and=C2=A0what variables are diffe=
rent(or indepentant).</div><div>But=C2=A0how can I deal with rvalues?=C2=A0=
For examples, 1 can be seen as a variable which is always 1.</div><div>But =
it has=C2=A0no name. It is just 1. It=C2=A0is always indepentant from other=
=C2=A0variables.</div><div>So I=C2=A0made it=C2=A0to consist of const lvalu=
e references, which=C2=A0can=C2=A0initialized=C2=A0with lvalue or rvalue.</=
div><div>But=C2=A0how can I determine it=C2=A0refers to lvalue or rvalue?? =
I couldn't find any solution from the standard library.</div></blockquo=
te></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" 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_54_312722975.1440211333637--
------=_Part_53_1393151064.1440211333630--
.
Author: David Krauss <potswa@gmail.com>
Date: Sat, 22 Aug 2015 12:03:55 +0800
Raw View
--Apple-Mail=_62997BD6-83E0-4C29-B190-5FD5C466B56A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
You=E2=80=99re basically reinventing expression templates. The solution to =
your stated problem of differentiating lvalues from rvalues is to alternate=
ly use member lvalue references (&) or rvalue references (&&), depending on=
the operator overloads that build the expression.
Another excerpt from my upcoming proposal:
> Expression templates with rvalue semantics
>=20
> Expression template libraries benefit from conserving memory and minimizi=
ng intermediate temporaries. If temporaries could be retained as persistent=
storage for results, expensive copy operations could be eliminated.
>=20
> A library designed this way would also be able to recycle memory from nam=
ed objects passed into an expression through std::move.
>=20
It=E2=80=99s a hopeful direction, but the language isn=E2=80=99t there yet.
But this optimization doesn=E2=80=99t seem to be what you=E2=80=99re after;=
it looks like you want easy alias analysis. Alias analysis is never easy. =
I think the best you can do is to compare object addresses. So, as for P(X<=
X=C2=B2), there could be a rule simplifying P(X<Y*Z) to P(1 < abs(X)) when =
&X =3D=3D &Y && &Y =3D=3D &Z. The optimizer should be able to evaluate such=
equality tests at compile time when X, Y, and Z are a mix of temporaries a=
nd local objects.
> On 2015=E2=80=9308=E2=80=9322, at 10:42 AM, NDos Dannyu <ndospark320@nave=
r.com> wrote:
>=20
> 2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=
=A4=EC=A0=84 11=EC=8B=9C 24=EB=B6=84 55=EC=B4=88 UTC+9, Thiago Macieira =EB=
=8B=98=EC=9D=98 =EB=A7=90:
>=20
> You're saying that the function doit above should return null if it was c=
alled=20
> with a reference to a temporary. But if it does so, how will it print the=
=20
> value that was referenced?=20
> Does printf need its address??=20
> Besides, we're missing an important aspect: why do you want this? What's =
the=20
> motivation?=20
> I'm writing my story again:
> I have a value class indicating a finite discrete random variable.
> But I had a problem. For example, assume that I have a variable named X.
> But how can P(X<X=C2=B2) interpreted? X is still X, even it is squared, i=
sn't it?
> Things will get much more complicated if I have multiple variables, X, Y =
and Z,
> and I have to do like P(X<X=C2=B2=3DY>|Z|) or something.=20
> So I decided to make a bind of variables.
> It would be a tree structure, consisting of other binds or variables.
> If it consists of references of variables, it will know what variables ar=
e same(or dependant) and what variables are different(or indepentant).
> But how can I deal with rvalues? For examples, 1 can be seen as a variabl=
e which is always 1.
> But it has no name. It is just 1. It is always indepentant from other var=
iables.
> So I made it to consist of const lvalue references, which can initialized=
with lvalue or rvalue.
> But how can I determine it refers to lvalue or rvalue?? I couldn't find a=
ny solution from the standard library.
--=20
---=20
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 e=
mail 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-proposa=
ls/.
--Apple-Mail=_62997BD6-83E0-4C29-B190-5FD5C466B56A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><div class=3D""><b=
r class=3D""></div>You=E2=80=99re basically reinventing expression template=
s. The solution to your stated problem of differentiating lvalues from rval=
ues is to alternately use member lvalue references (<span style=3D"fon=
t-family: Courier;" class=3D"">&</span>) or rvalue references (<sp=
an style=3D"font-family: Courier;" class=3D"">&&</span>), depending=
on the operator overloads that build the expression.<div class=3D""><br cl=
ass=3D""></div><div class=3D"">Another excerpt from my upcoming proposal:</=
div><div class=3D""><br class=3D""></div><div class=3D""><div class=3D""><b=
lockquote type=3D"cite" style=3D"font-size: 13px;" class=3D""><font color=
=3D"#5856d6" class=3D"">Expression templates with rvalue semantics</font></=
blockquote><blockquote type=3D"cite" class=3D""><br class=3D""></blockquote=
></div><blockquote type=3D"cite" class=3D""><p style=3D"margin: 0px 0px 6px=
; -webkit-text-stroke-color: rgb(0, 0, 0); -webkit-text-stroke-width: initi=
al;" class=3D"">Expression template libraries benefit from conserving memor=
y and minimizing intermediate temporaries. If temporaries could be retained=
as persistent storage for results, expensive copy operations could be elim=
inated.</p><p style=3D"margin: 0px 0px 16px; -webkit-text-stroke-color: rgb=
(0, 0, 0); -webkit-text-stroke-width: initial;" class=3D"">A library design=
ed this way would also be able to recycle memory from named objects passed =
into an expression through <span style=3D"font-size: 11px; font-family: Cou=
rier; background-color: rgb(245, 245, 245);" class=3D"">std::move</span>.</=
p></blockquote><div class=3D""><br class=3D""></div><div class=3D"">It=E2=
=80=99s a hopeful direction, but the language isn=E2=80=99t there yet.</div=
><div class=3D""><br class=3D""></div><div class=3D"">But this optimization=
doesn=E2=80=99t seem to be what you=E2=80=99re after; it looks like you wa=
nt easy alias analysis. Alias analysis is never easy. I think the best you =
can do is to compare object addresses. So, as for P(X<X=C2=B2), there co=
uld be a rule simplifying <font face=3D"Courier" class=3D"">P(X<Y*Z)</fo=
nt> to <font face=3D"Courier" class=3D"">P(1 < abs(X))</font> when <font=
face=3D"Courier" class=3D"">&X =3D=3D &Y && &Y =3D=3D =
&Z</font>. The optimizer should be able to evaluate such equality tests=
at compile time when X, Y, and Z are a mix of temporaries and local object=
s.</div><div class=3D""><br class=3D""></div><div class=3D""><br class=3D""=
></div><div class=3D""><div><blockquote type=3D"cite" class=3D""><div class=
=3D"">On 2015=E2=80=9308=E2=80=9322, at 10:42 AM, NDos Dannyu <<a href=
=3D"mailto:ndospark320@naver.com" class=3D"">ndospark320@naver.com</a>> =
wrote:</div><div class=3D""><div dir=3D"ltr" class=3D""><br class=3D"">2015=
=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=A4=EC=
=A0=84 11=EC=8B=9C 24=EB=B6=84 55=EC=B4=88 UTC+9, Thiago Macieira =EB=8B=98=
=EC=9D=98 =EB=A7=90:<blockquote class=3D"gmail_quote" style=3D"margin: 0px =
0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); bo=
rder-left-width: 1px; border-left-style: solid;"><br class=3D"">You're sayi=
ng that the function doit above should return null if it was called=20
<br class=3D"">with a reference to a temporary. But if it does so, how will=
it print the=20
<br class=3D"">value that was referenced?
<br class=3D""></blockquote><div class=3D"">Does printf need its addre=
ss?? </div><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px =
0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border=
-left-width: 1px; border-left-style: solid;">Besides, we're missing an impo=
rtant aspect: why do you want this? What's the=20
<br class=3D"">motivation?
<br class=3D""></blockquote><div class=3D"">I'm writing my story again:</di=
v><div class=3D""><blockquote style=3D"margin-right: 0px;" dir=3D"ltr" clas=
s=3D""><div class=3D""><font class=3D"">I have a value class indicating a f=
inite discrete random variable.</font></div><div class=3D"">But I had a pro=
blem. For example, assume that I have a variable named X.</div><div cl=
ass=3D"">But how can P(X<X=C2=B2) interpreted? X is still=
X, even it is squared, isn't it?</div><div class=3D"">Things will get much=
more complicated if I have multiple variables, X, Y and Z,</div><div =
class=3D"">and I have to do like P(X<X=C2=B2=3DY>|Z|) or something.&n=
bsp;</div><div class=3D"">So I decided to make a bind of variables.</d=
iv><div class=3D"">It would be a tree structure, consisting of other&n=
bsp;binds or variables.</div><div class=3D"">If it consists&=
nbsp;of references of variables, it will know what variables are same(or de=
pendant) and what variables are different(or indepentant).</div><div c=
lass=3D"">But how can I deal with rvalues? For examples, 1 can be=
seen as a variable which is always 1.</div><div class=3D"">But it has =
;no name. It is just 1. It is always indepentant from other varia=
bles.</div><div class=3D"">So I made it to consist of const lvalu=
e references, which can initialized with lvalue or rvalue.</=
div><div class=3D"">But how can I determine it refers to lvalue o=
r rvalue?? I couldn't find any solution from the standard library.</div></b=
lockquote></div></div></div></blockquote></div></div></div></body></html>
<p></p>
-- <br />
<br />
--- <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 />
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 />
--Apple-Mail=_62997BD6-83E0-4C29-B190-5FD5C466B56A--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Fri, 21 Aug 2015 21:06:23 -0700
Raw View
On Friday 21 August 2015 19:42:13 NDos Dannyu wrote:
> 2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=
=A4=EC=A0=84 11=EC=8B=9C 24=EB=B6=84 55=EC=B4=88 UTC+9, Thiago Macieira =EB=
=8B=98=EC=9D=98 =EB=A7=90:
> > You're saying that the function doit above should return null if it was
> > called
> > with a reference to a temporary. But if it does so, how will it print t=
he
> > value that was referenced?
>=20
> Does printf need its address??
No. The point is that the function "doit" needs to know how to obtain the=
=20
value, regardless of whether it's a reference to a temporary or a reference=
to=20
something more permanent.
> > Besides, we're missing an important aspect: why do you want this? What'=
s
> > the
> > motivation?
>=20
> I'm writing my story again:
>=20
> I have a value class indicating a finite discrete random variable.
> But I had a problem. For example, assume that I have a variable named X.
> But how can P(X<X=C2=B2) interpreted? X is still X, even it is squared, i=
sn't it?
> Things will get much more complicated if I have multiple variables, X, Y
> and Z,
> and I have to do like P(X<X=C2=B2=3DY>|Z|) or something.
What's is P and what is squaring the variable here? How should I interpret =
the=20
equal sign above?
> So I decided to make a bind of variables.
> It would be a tree structure, consisting of other binds or variables.
> If it consists of references of variables, it will know what variables ar=
e
> same(or dependant) and what variables are different(or indepentant).
> But how can I deal with rvalues? For examples, 1 can be seen as a variabl=
e
> which is always 1.
Correct.
> But it has no name. It is just 1. It is always indepentant from
> other variables.
Right. It may also be different from other 1s.
> So I made it to consist of const lvalue references,
> which can initialized with lvalue or rvalue.
> But how can I determine it refers to lvalue or rvalue?? I couldn't find a=
ny
> solution from the standard library.
You cannot.
--=20
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--=20
---=20
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 e=
mail 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-proposa=
ls/.
.
Author: NDos Dannyu <ndospark320@naver.com>
Date: Fri, 21 Aug 2015 22:15:57 -0700 (PDT)
Raw View
------=_Part_537_790931100.1440220558026
Content-Type: multipart/alternative;
boundary="----=_Part_538_1646266657.1440220558026"
------=_Part_538_1646266657.1440220558026
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=A4=
=ED=9B=84 1=EC=8B=9C 6=EB=B6=84 29=EC=B4=88 UTC+9, Thiago Macieira =EB=8B=
=98=EC=9D=98 =EB=A7=90:
>
>
> What's is P and what is squaring the variable here? How should I interpre=
t=20
> the=20
> equal sign above?=20
>
P is probability function. It calculates the probability that the=20
expression inside is true.
For example:
*#include <random>*
*discrete_random_variable<int>=20
X(std::uniform_int_distribution<int>(1,6));*
This is a variable that represents a die.
P(X=3D1) =3D 1/6, P(X=3D2) =3D 1/6, ... , P(X=3D6) =3D 1/6.
But what would P(X=3DX) be?
Of course a die will always be same number with itself, so P(X=3DX) =3D 1.=
=20
But...
*discrete_random_variable<int> Y(X);*
This is a copy of X. Now I have two dice.
Even Y is a perfect copy of X, the dice are different.
P(X=3DY) =3D 1/6.
Of course, C++ uses =3D=3D as equality, and C++ can't compare three or more=
=20
elements at once.
So, the expression P(X<X=C2=B2=3DY>|Z|) would be written in C++ as somethin=
g like=20
this:
*compare(And{{X, std::less, bind_variable(std::pow, X, 2)}, {**bind_var=
iable(std::pow,=20
X, 2), std::equal, Y}, {Y, std::greater, bind_variable(std::abs, Z)}});*
What a mess.
>
> You cannot.=20
>
That was harsh... >_> Maybe I should use pointers instead, as David Krauss=
=20
pointed it. Thank you David Krauss.
--=20
---=20
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 e=
mail 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-proposa=
ls/.
------=_Part_538_1646266657.1440220558026
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=
=9A=94=EC=9D=BC =EC=98=A4=ED=9B=84 1=EC=8B=9C 6=EB=B6=84 29=EC=B4=88 UTC+9,=
Thiago Macieira =EB=8B=98=EC=9D=98 =EB=A7=90:<blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-col=
or: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;">=
<br>What's is P and what is squaring the variable here? How should I in=
terpret the=20
<br>equal sign above?
<br></blockquote><div>P is probability function. It calculates the probabil=
ity that the expression inside=C2=A0is true.</div><div>For example:</div><d=
iv>=C2=A0=C2=A0=C2=A0 <strong>#include <random></strong></div><div>=
=C2=A0=C2=A0=C2=A0 <strong>discrete_random_variable<int> X(std::unifo=
rm_int_distribution<int>(1,6));</strong></div><div>This is a variable=
that represents a die.</div><div>P(X=3D1)=C2=A0=3D 1/6, P(X=3D2) =3D 1/6, =
.... , P(X=3D6) =3D 1/6.</div><div>But what would P(X=3DX) be?</div><div>Of =
course a die will always be same number with itself, so P(X=3DX) =3D 1. But=
....</div><div>=C2=A0=C2=A0=C2=A0 <strong>discrete_random_variable<int>=
; Y(X);</strong></div><div>This is a copy of X. Now I have two dice.</div><=
div>Even Y is a perfect copy of X, the dice are different.</div><div>P(X=3D=
Y) =3D 1/6.</div><div>Of course, C++ uses =3D=3D as equality, and C++ can&#=
39;t compare three or more elements at once.</div><div>So, the expression P=
(X<X=C2=B2=3DY>|Z|) would be written=C2=A0in C++=C2=A0as something=C2=
=A0like this:</div><div>=C2=A0=C2=A0=C2=A0 <strong>compare(And{{X, std::les=
s, bind_variable(std::pow, X, 2)}, {</strong><strong>bind_variable(std::pow=
, X, 2), std::equal, Y}, {Y, std::greater, bind_variable(std::abs, Z)}});</=
strong></div><div>What a mess.</div><blockquote class=3D"gmail_quote" style=
=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(20=
4, 204, 204); border-left-width: 1px; border-left-style: solid;"><br>You ca=
nnot.
<br></blockquote><div>That was harsh... >_> Maybe I should use pointe=
rs instead, as David=C2=A0Krauss pointed it. Thank you David Krauss.</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" 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_538_1646266657.1440220558026--
------=_Part_537_790931100.1440220558026--
.
Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Mon, 24 Aug 2015 12:09:57 -0700 (PDT)
Raw View
------=_Part_3154_1864411866.1440443397674
Content-Type: multipart/alternative;
boundary="----=_Part_3155_218057942.1440443397674"
------=_Part_3155_218057942.1440443397674
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Friday, August 21, 2015 at 10:15:58 PM UTC-7, NDos Dannyu wrote:
>
> 2015=EB=85=84 8=EC=9B=94 22=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=
=A4=ED=9B=84 1=EC=8B=9C 6=EB=B6=84 29=EC=B4=88 UTC+9, Thiago Macieira =EB=
=8B=98=EC=9D=98 =EB=A7=90:
>>
>>
>> What's is P and what is squaring the variable here? How should I=20
>> interpret the=20
>> equal sign above?=20
>>
> P is probability function. It calculates the probability that the=20
> expression inside is true.
> For example:
> *#include <random>*
> *discrete_random_variable<int>=20
> X(std::uniform_int_distribution<int>(1,6));*
> This is a variable that represents a die.
> P(X=3D1) =3D 1/6, P(X=3D2) =3D 1/6, ... , P(X=3D6) =3D 1/6.
> But what would P(X=3DX) be?
> Of course a die will always be same number with itself, so P(X=3DX) =3D 1=
..=20
> But...
> *discrete_random_variable<int> Y(X);*
> This is a copy of X. Now I have two dice.
> Even Y is a perfect copy of X, the dice are different.
> P(X=3DY) =3D 1/6.
>
You started off by claiming that you were trying to implement a "value=20
type"; but what you have here is definitely NOT a value type, because you=
=20
want Y to be equal to X (i.e. Y is a copy of X), yet Y behaves differently=
=20
from X. That's the very definition of "not a value type."
You're basically trying to have the lexical name of the C++ variable=20
*holding* the value *be part of* the value: the fact that the variable=20
holding your object happens to be named X is part of the semantics of the=
=20
object.
I strongly recommend that you don't abuse C++ in this way. You want=20
something like this:
discrete_random_variable<int>=20
X(std::uniform_int_distribution<int>(1,6));
discrete_random_variable<int> identicalWithX =3D X;
discrete_random_variable<int> Y =3D X.makeIndependentCopy();
assert(P(X =3D=3D X) =3D=3D 1.0);
assert(P(X =3D=3D Y) =3D=3D 0.16666666);
=20
> Of course, C++ uses =3D=3D as equality, and C++ can't compare three or mo=
re=20
> elements at once.
> So, the expression P(X<X=C2=B2=3DY>|Z|) would be written in C++ as someth=
ing like=20
> this:
> *compare(And{{X, std::less, bind_variable(std::pow, X, 2)}, {**bind_v=
ariable(std::pow,=20
> X, 2), std::equal, Y}, {Y, std::greater, bind_variable(std::abs, Z)}});*
> What a mess.
>
I'd prefer to write the above as
discrete_random_variable<bool> B =3D (X < X*X && X*X =3D=3D Y && Y > ab=
s(Z));
double p =3D P(B);
which is perfectly doable with operator overloading.
This kind of question ("how do I write this specific kind of numeric code=
=20
in C++?") would be more suited for StackOverflow or=20
CodeReview.stackexchange.com, as opposed to this forum, which is more for=
=20
proposed new language features and suchlike.
HTH,
=E2=80=93Arthur
--=20
---=20
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 e=
mail 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-proposa=
ls/.
------=_Part_3155_218057942.1440443397674
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Friday, August 21, 2015 at 10:15:58 PM UTC-7, NDos Dannyu wrote:<blockqu=
ote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left=
: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">2015=EB=85=84 8=EC=9B=
=94 22=EC=9D=BC =ED=86=A0=EC=9A=94=EC=9D=BC =EC=98=A4=ED=9B=84 1=EC=8B=9C 6=
=EB=B6=84 29=EC=B4=88 UTC+9, Thiago Macieira =EB=8B=98=EC=9D=98 =EB=A7=90:<=
blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;padding-=
left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-le=
ft-style:solid"><br>What's is P and what is squaring the variable here?=
How should I interpret the=20
<br>equal sign above?
<br></blockquote><div>P is probability function. It calculates the probabil=
ity that the expression inside=C2=A0is true.</div><div>For example:</div><d=
iv>=C2=A0=C2=A0=C2=A0 <strong>#include <random></strong></div><div>=
=C2=A0=C2=A0=C2=A0 <strong>discrete_random_variable<int> X(std::unifo=
rm_int_<wbr>distribution<int>(1,6));</strong></div><div>This is a var=
iable that represents a die.</div><div>P(X=3D1)=C2=A0=3D 1/6, P(X=3D2) =3D =
1/6, ... , P(X=3D6) =3D 1/6.</div><div>But what would P(X=3DX) be?</div><di=
v>Of course a die will always be same number with itself, so P(X=3DX) =3D 1=
.. But...</div><div>=C2=A0=C2=A0=C2=A0 <strong>discrete_random_variable<i=
nt> Y(X);</strong></div><div>This is a copy of X. Now I have two dice.</=
div><div>Even Y is a perfect copy of X, the dice are different.</div><div>P=
(X=3DY) =3D 1/6.</div></div></blockquote><div><br></div><div>You started of=
f by claiming that you were trying to implement a "value type"; b=
ut what you have here is definitely NOT a value type, because you want Y to=
be equal to X (i.e. Y is a copy of X), yet Y behaves differently from X. T=
hat's the very definition of "not a value type."</div><div><b=
r></div><div>You're basically trying to have the lexical name of the C+=
+ variable <i>holding</i> the value <i>be part of</i> the value: the fact t=
hat the variable holding your object happens to be named <font face=3D"cour=
ier new, monospace">X</font> is part of the semantics of the object.</div><=
div><br></div><div>I strongly recommend that you don't abuse C++ in thi=
s way. You want something like this:</div><div><br></div><div>=C2=A0 =C2=A0=
discrete_random_variable<int> X(std::uniform_int_distribution<int=
>(1,6));<br></div><div><div>=C2=A0 =C2=A0 discrete_random_variable<in=
t> identicalWithX =3D X;</div><div>=C2=A0 =C2=A0 discrete_random_variabl=
e<int> Y =3D X.makeIndependentCopy();</div><div><div>=C2=A0 =C2=A0 as=
sert(P(X =3D=3D X) =3D=3D 1.0);</div></div></div><div><div>=C2=A0 =C2=A0 as=
sert(P(X =3D=3D Y) =3D=3D 0.16666666);</div></div><div>=C2=A0<br></div><blo=
ckquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-=
left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>Of course, C=
++ uses =3D=3D as equality, and C++ can't compare three or more element=
s at once.</div><div>So, the expression P(X<X=C2=B2=3DY>|Z|) would be=
written=C2=A0in C++=C2=A0as something=C2=A0like this:</div><div>=C2=A0=C2=
=A0=C2=A0 <strong>compare(And{{X, std::less, bind_variable(std::pow, X, 2)}=
, {</strong><strong>bind_variable(std::pow, X, 2), std::equal, Y}, {Y, std:=
:greater, bind_variable(std::abs, Z)}});</strong></div><div>What a mess.</d=
iv></div></blockquote><div><br></div><div>I'd prefer to write the above=
as</div><div><br></div><div>=C2=A0 =C2=A0 discrete_random_variable<bool=
> B =3D (X < X*X && X*X =3D=3D Y && Y > abs(Z));</=
div><div>=C2=A0 =C2=A0 double p =3D P(B);</div><div><br></div><div>which is=
perfectly doable with operator overloading.</div><div><br></div><div>This =
kind of question ("how do I write this specific kind of numeric code i=
n C++?") would be more suited for StackOverflow or CodeReview.stackexc=
hange.com, as opposed to this forum, which is more for proposed new languag=
e features and suchlike.</div><div><br></div><div>HTH,</div><div>=E2=80=93A=
rthur</div>
<p></p>
-- <br />
<br />
--- <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 />
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_3155_218057942.1440443397674--
------=_Part_3154_1864411866.1440443397674--
.