220 19982 <502d5927-226c-45cd-a18b-c3bd92455759@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Address of a reference: determining the value
 category of what it refers?
Date: Mon, 24 Aug 2015 12:09:57 -0700 (PDT)
Lines: 182
Approved: news@gmane.org
Message-ID: <502d5927-226c-45cd-a18b-c3bd92455759@isocpp.org>
References: <76fe342f-3342-4355-af20-1c41b21e54aa@isocpp.org> <3183929.eXnTES4BH3@tjmaciei-mobl4> <c817b9fc-7a99-44ec-96a0-97379d0f17a7@isocpp.org>
 <13312961.n5JFXrPRMR@tjmaciei-mobl4>
 <1c31275e-3bac-4eb2-99cf-256b14e6f650@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_3154_1864411866.1440443397674"
X-Trace: ger.gmane.org 1440443417 26801 80.91.229.3 (24 Aug 2015 19:10:17 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 24 Aug 2015 19:10:17 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDLZJYWNDQIINWHNVYCRUBCYS7ZBC@isocpp.org Mon Aug 24 21:10:01 2015
Return-path: <std-proposals+bncBDLZJYWNDQIINWHNVYCRUBCYS7ZBC@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f200.google.com ([209.85.220.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDLZJYWNDQIINWHNVYCRUBCYS7ZBC@isocpp.org>)
	id 1ZTx84-0000fb-LK
	for gclcip-std-proposals@m.gmane.org; Mon, 24 Aug 2015 21:10:00 +0200
Original-Received: by qkcu126 with SMTP id u126sf205689909qkc.0
        for <gclcip-std-proposals@m.gmane.org>; Mon, 24 Aug 2015 12:09:59 -0700 (PDT)
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
         :content-type: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=va9ftjSAVOOXmL+XtB2yUVJHNT6bNYV37jfIHX7AYBk=;
        b=zswOw6YS9sumqjeSfGqhJ9qgn67agA/AXpKoRwiq5smUYVw+NL2/cFWFiYMeeE7YSv
         Z9tUT9TDsH5phiZ7wYVP89enleAw7lgP1ICw2mshhemXH219I6vwManN5fbsTV3YHAM+
         V9kn6/7Obox06TMSdspcM1f/I4+DWyrkFgFVF2QqenKEy+cJLR8JegwbEiDcS9uv4ULP
         W/TSTAjwArF3JlrngYm2PadfU2ncQ2UxulUrSRI6/RmPQ3CZ+Zh7kWGWevVEwkABvc6A
         gGznNbRcx8DTtaH7ZoNaFrT5/44isn+L+V6ciSi4NwZTvUkcczjWe61QzgnC22dVAKJ+
         b/Ew==
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:content-type: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=va9ftjSAVOOXmL+XtB2yUVJHNT6bNYV37jfIHX7AYBk=;
        b=cbcyFOyhIf0N4lytRrJtxmwTNqbu1Z5KJPI/F0wiSpSbM6PrCBKSeADqjObh1o+SNI
         7u7bbNkHZwBDO95hJpGIR2cJTQp4plW+FdIUB4fUUt91GsUv3lamOV/z8mTiORgsy+7p
         yUeT9TWyrjnMYvWqXOJ1wEPfd7F8e107mnAHNI0u4zPXJuE/CdcL77/Xn/2BWALzlBaf
         2Rigc+Rsx7tM7I5Bqxjpiv5WqHrpdVnnbyQPx0VjsIK9ebfVD0xreic8eXLMtpUQgN4S
         n4VccS7tIKR46UHN033axc5QD2/DjTwBE31xjf/YlrNgdpkmGPt7pwtcEzRzLqG9qcKK
         ZKIA==
X-Gm-Message-State: ALoCoQkqkfTyzl0Ykwhyq2aANROnL2YkpVlk+VONzhrvf3JEOoZ9gN/yFA1gs57UxUG/8h6DNir1
X-Received: by 10.129.83.136 with SMTP id h130mr23912888ywb.23.1440443399624;
        Mon, 24 Aug 2015 12:09:59 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.129.38 with SMTP id c38ls1446903iod.15.gmail; Mon, 24 Aug
 2015 12:09:58 -0700 (PDT)
X-Received: by 10.50.62.68 with SMTP id w4mr273901igr.12.1440443398696;
        Mon, 24 Aug 2015 12:09:58 -0700 (PDT)
In-Reply-To: <1c31275e-3bac-4eb2-99cf-256b14e6f650@isocpp.org>
X-Original-Sender: arthur.j.odwyer@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:19982
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19982>

------=_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&#39;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 &lt;random&gt;</strong></div><div>=
=C2=A0=C2=A0=C2=A0 <strong>discrete_random_variable&lt;int&gt; X(std::unifo=
rm_int_<wbr>distribution&lt;int&gt;(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&lt;i=
nt&gt; 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 &quot;value type&quot;; 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&#39;s the very definition of &quot;not a value type.&quot;</div><div><b=
r></div><div>You&#39;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&#39;t abuse C++ in thi=
s way. You want something like this:</div><div><br></div><div>=C2=A0 =C2=A0=
 discrete_random_variable&lt;int&gt; X(std::uniform_int_distribution&lt;int=
&gt;(1,6));<br></div><div><div>=C2=A0 =C2=A0 discrete_random_variable&lt;in=
t&gt; identicalWithX =3D X;</div><div>=C2=A0 =C2=A0 discrete_random_variabl=
e&lt;int&gt; 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&#39;t compare three or more element=
s at once.</div><div>So, the expression P(X&lt;X=C2=B2=3DY&gt;|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&#39;d prefer to write the above=
 as</div><div><br></div><div>=C2=A0 =C2=A0 discrete_random_variable&lt;bool=
&gt; B =3D (X &lt; X*X &amp;&amp; X*X =3D=3D Y &amp;&amp; Y &gt; 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 (&quot;how do I write this specific kind of numeric code i=
n C++?&quot;) 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&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_3155_218057942.1440443397674--
------=_Part_3154_1864411866.1440443397674--

.
