220 19957 <9CEC4FAB-0198-4CB9-929E-57FD48BA1D6B@gmail.com> article
Path: news.gmane.org!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Address of a reference: determining the value
 category of what it refers?
Date: Sat, 22 Aug 2015 12:03:55 +0800
Lines: 181
Approved: news@gmane.org
Message-ID: <9CEC4FAB-0198-4CB9-929E-57FD48BA1D6B@gmail.com>
References: <76fe342f-3342-4355-af20-1c41b21e54aa@isocpp.org> <CAOfiQqnohbBZt9OguvL8Tg=9cDPzEzTPC_hAkdErM9T_mnH6vw@mail.gmail.com> <d48969a2-f27a-4c82-869e-6a848c9f1422@isocpp.org> <3183929.eXnTES4BH3@tjmaciei-mobl4> <c817b9fc-7a99-44ec-96a0-97379d0f17a7@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\))
Content-Type: multipart/alternative; boundary="Apple-Mail=_62997BD6-83E0-4C29-B190-5FD5C466B56A"
X-Trace: ger.gmane.org 1440216254 8955 80.91.229.3 (22 Aug 2015 04:04:14 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 22 Aug 2015 04:04:14 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBNPJ36XAKGQEI64VGUA@isocpp.org Sat Aug 22 06:04:09 2015
Return-path: <std-proposals+bncBCW25A7E3QCRBNPJ36XAKGQEI64VGUA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oi0-f69.google.com ([209.85.218.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBNPJ36XAKGQEI64VGUA@isocpp.org>)
	id 1ZT02J-0007nG-4k
	for gclcip-std-proposals@m.gmane.org; Sat, 22 Aug 2015 06:04:07 +0200
Original-Received: by oiew67 with SMTP id w67sf125469452oie.0
        for <gclcip-std-proposals@m.gmane.org>; Fri, 21 Aug 2015 21:04:06 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:content-type:message-id:mime-version
         :subject:date:references:to:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=NytDQcnazi7u+LEvQDe0FyXCIeIP6Zml7l82gjF5BIY=;
        b=bBZApPxcMnQlo0iatj71aTG2M17zSEIE9lgm90waQqklye9ElplLUIuwt4AkCS8YCn
         lmL6qeIt9JEfgsJ9/qEnRTOmxo/9z4ZIuc+gJ7u+VJPy160Bn/QJfxDrxWnkKYIg7ZHU
         uKInbiyB5I4X+FP40+b6JVm9UXxplfZZIDalG5ptdUInqyn/Ng/b+yinSJJ8qA1ysxtD
         Rit3i7V6EInRZthAzz1KlcJfB3DYMeipD+CG5HE0pzgmWqkSvmnZH1/NrITAVwMOVNt0
         cTVzVsriQH3VaXrE19UkK0hcaWx7fjQ1wTbXWJOIliGG/PeYqCR0XCfMj7Mg8BbOnK6D
         L3vQ==
X-Gm-Message-State: ALoCoQnbCuu0MbR7J4zRoJmvXG7w8GzC6DROp5jldHyGuVbu+naYfJM0u/qEOvYoz/6FMXUBWsbY
X-Received: by 10.50.128.163 with SMTP id np3mr5899825igb.3.1440216246239;
        Fri, 21 Aug 2015 21:04:06 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.29.36 with SMTP id g4ls653439igh.31.canary; Fri, 21 Aug
 2015 21:04:05 -0700 (PDT)
X-Received: by 10.68.68.175 with SMTP id x15mr23990114pbt.10.1440216245439;
        Fri, 21 Aug 2015 21:04:05 -0700 (PDT)
Original-Received: from mail-pa0-x231.google.com (mail-pa0-x231.google.com. [2607:f8b0:400e:c03::231])
        by mx.google.com with ESMTPS id p4si16374131pdo.42.2015.08.21.21.04.05
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Fri, 21 Aug 2015 21:04:05 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:400e:c03::231 as permitted sender) client-ip=2607:f8b0:400e:c03::231;
Original-Received: by pacgr6 with SMTP id gr6so6880664pac.0
        for <std-proposals@isocpp.org>; Fri, 21 Aug 2015 21:04:05 -0700 (PDT)
X-Received: by 10.66.219.39 with SMTP id pl7mr23823049pac.148.1440216244906;
        Fri, 21 Aug 2015 21:04:04 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.44.90])
        by smtp.gmail.com with ESMTPSA id ob4sm9422593pbb.40.2015.08.21.21.04.01
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Fri, 21 Aug 2015 21:04:04 -0700 (PDT)
In-Reply-To: <c817b9fc-7a99-44ec-96a0-97379d0f17a7@isocpp.org>
X-Mailer: Apple Mail (2.2098)
X-Original-Sender: potswa@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of potswa@gmail.com designates 2607:f8b0:400e:c03::231 as permitted
 sender) smtp.mailfrom=potswa@gmail.com;       dkim=pass header.i=@gmail.com;
       dmarc=pass (p=NONE dis=NONE) header.from=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:19957
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19957>

--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&nbsp;lvalue references (<span style=3D"fon=
t-family: Courier;" class=3D"">&amp;</span>) or&nbsp;rvalue references (<sp=
an style=3D"font-family: Courier;" class=3D"">&amp;&amp;</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&lt;X=C2=B2), there co=
uld be a rule simplifying <font face=3D"Courier" class=3D"">P(X&lt;Y*Z)</fo=
nt> to <font face=3D"Courier" class=3D"">P(1 &lt; abs(X))</font> when <font=
 face=3D"Courier" class=3D"">&amp;X =3D=3D &amp;Y &amp;&amp; &amp;Y =3D=3D =
&amp;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 &lt;<a href=
=3D"mailto:ndospark320@naver.com" class=3D"">ndospark320@naver.com</a>&gt; =
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&nbsp;printf need its addre=
ss??&nbsp;</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&nbsp;I have a variable named X.</div><div cl=
ass=3D"">But&nbsp;how&nbsp;can&nbsp;P(X&lt;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&nbsp;I have multiple variables, X, Y and Z,</div><div =
class=3D"">and I have to do like P(X&lt;X=C2=B2=3DY&gt;|Z|) or something.&n=
bsp;</div><div class=3D"">So I decided to&nbsp;make a bind of variables.</d=
iv><div class=3D"">It would be a tree structure, consisting of&nbsp;other&n=
bsp;binds&nbsp;or variables.</div><div class=3D"">If&nbsp;it&nbsp;consists&=
nbsp;of references of variables, it will know what variables are same(or de=
pendant) and&nbsp;what variables are different(or indepentant).</div><div c=
lass=3D"">But&nbsp;how can I deal with rvalues?&nbsp;For examples, 1 can be=
 seen as a variable which is always 1.</div><div class=3D"">But it has&nbsp=
;no name. It is just 1. It&nbsp;is always indepentant from other&nbsp;varia=
bles.</div><div class=3D"">So I&nbsp;made it&nbsp;to consist of const lvalu=
e references, which&nbsp;can&nbsp;initialized&nbsp;with lvalue or rvalue.</=
div><div class=3D"">But&nbsp;how can I determine it&nbsp;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&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 />

--Apple-Mail=_62997BD6-83E0-4C29-B190-5FD5C466B56A--

.
