220 19949 <76fe342f-3342-4355-af20-1c41b21e54aa@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: NDos Dannyu <ndospark320@naver.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Address of a reference: determining the value
 category of what it refers?
Date: Fri, 21 Aug 2015 16:24:30 -0700 (PDT)
Lines: 155
Approved: news@gmane.org
Message-ID: <76fe342f-3342-4355-af20-1c41b21e54aa@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_110_1071755105.1440199470671"
X-Trace: ger.gmane.org 1440199475 10284 80.91.229.3 (21 Aug 2015 23:24:35 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 21 Aug 2015 23:24:35 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCX7FRO67EHRBMHG32XAKGQEJE5J64A@isocpp.org Sat Aug 22 01:24:34 2015
Return-path: <std-proposals+bncBCX7FRO67EHRBMHG32XAKGQEJE5J64A@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oi0-f71.google.com ([209.85.218.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCX7FRO67EHRBMHG32XAKGQEJE5J64A@isocpp.org>)
	id 1ZSvfl-00033u-P8
	for gclcip-std-proposals@m.gmane.org; Sat, 22 Aug 2015 01:24:33 +0200
Original-Received: by oifo84 with SMTP id o84sf118958261oif.3
        for <gclcip-std-proposals@m.gmane.org>; Fri, 21 Aug 2015 16:24:33 -0700 (PDT)
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: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=FHeslqp8Hvw6y7LQ/XfUgQcseAsdALlphhDKzPDrB7o=;
        b=l1R+1wvBuaO4xlj8CxafWQuUZBijO90r8BRcta3Hdhs/O8R5Pi2aSZa6FHlh1tT+aJ
         pNv0ILE5quVv+GhIsQ+DVUr89N509WDLfSdjvvf3LjLvMx6CN1iWIXI6oQdRoB0xKk1b
         lAp7OY+6pYYI6qx9pbzXQP2lIqKoYCBdNaidTjo49buISQwJ0I/vQe2ZimmA1oEC7fBB
         7tRWDwCabG7MHqx1lmoKWFC9hts9wZCW/yPq85FxMAyRmYPlA24cj4mhAFtDbF4CpuQK
         zE+meLY2GxDS4IepIYG7RqrsAoDJjABVA2V00G82aM5i1eTSq6YKzQbs9qy0srUyV1Bc
         T3Pg==
X-Gm-Message-State: ALoCoQmSjwoVDSkYlE0TkAz4j9JjAG2A4yUmRE5CM837QFXRTlF1KtAw+U/tlLc1CJG/9klSJu8Z
X-Received: by 10.50.3.97 with SMTP id b1mr5049636igb.10.1440199472986;
        Fri, 21 Aug 2015 16:24:32 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.131.17 with SMTP id f17ls925242iod.24.gmail; Fri, 21 Aug
 2015 16:24:32 -0700 (PDT)
X-Received: by 10.50.50.167 with SMTP id d7mr112712igo.10.1440199472244;
        Fri, 21 Aug 2015 16:24:32 -0700 (PDT)
X-Original-Sender: ndospark320@naver.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:19949
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19949>

------=_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&#39;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 &amp;lcr(=
i);</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 const int &amp;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 &lt;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 &amp;r1(=
i);</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 i=
nt &amp;r2(i);</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 std::printf(&quot;%p %p\n&quot;, (void *)&amp;r1, (void *)&amp;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 &lt;cstdio&gt;</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 &amp;r(i);</st=
rong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 const in=
t &amp;lcr(i);</strong></div><div><strong>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 const int &amp;rcr(0);</strong></div><div><strong>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 int &amp;&amp;rr(0);</strong></div><div><strong=
>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::printf(&quot;%p %p %p %p\n=
&quot;, (void *)&amp;r, (void *)&amp;lcr</strong><strong>&quot;, (void *)&a=
mp;rcr, (void *)&amp;rr</strong><strong>);</strong></div><div><strong>=C2=
=A0=C2=A0=C2=A0 }</strong></div><div>&amp;r and &amp;lcr prints out &amp;i,=
 but &amp;rcr and &amp;rr have their own unique value. It doesn&#39;t make =
sense, as what rcr and rr refer to are what don&#39;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 &lt;class T&gt;</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 T *oper=
ator &amp; (/* 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 &lt;class T&gt;</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 =
const T *operator &amp; (/* 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 &lt;class T&gt;</strong></div><div><strong>=
=C2=A0=C2=A0=C2=A0 T *operator &amp; (/* 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 &lt;class T=
&gt;</strong></div><div><strong>=C2=A0=C2=A0=C2=A0 const T *operator &amp; =
(/* 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 &lt;class T&gt;</strong></div><div><strong>=C2=A0=C2=A0=
=C2=A0 T *operator &amp; (/* 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&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_111_1680266912.1440199470672--
------=_Part_110_1071755105.1440199470671--

.
