220 12665 <574eee30-46d0-433f-b572-65b6844e2d8e@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Matthew Fioravante <fmatthew5876@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Templated *this
Date: Wed, 3 Sep 2014 18:57:39 -0700 (PDT)
Lines: 177
Approved: news@gmane.org
Message-ID: <574eee30-46d0-433f-b572-65b6844e2d8e@isocpp.org>
References: <CAGsORuB6Bz+vjD1ddNNJ6t5GBmdff3xKMe6HkY549=05gzjB9w@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_5088_1602156432.1409795859875"
X-Trace: ger.gmane.org 1409795868 21644 80.91.229.3 (4 Sep 2014 01:57:48 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 4 Sep 2014 01:57:48 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDELF54RTIGRBFEOT6QAKGQEW4IPBDY@isocpp.org Thu Sep 04 03:57:44 2014
Return-path: <std-proposals+bncBDELF54RTIGRBFEOT6QAKGQEW4IPBDY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f199.google.com ([209.85.214.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDELF54RTIGRBFEOT6QAKGQEW4IPBDY@isocpp.org>)
	id 1XPMIw-0003VQ-FF
	for gclcip-std-proposals@m.gmane.org; Thu, 04 Sep 2014 03:57:42 +0200
Original-Received: by mail-ob0-f199.google.com with SMTP id wn1sf49336070obc.2
        for <gclcip-std-proposals@m.gmane.org>; Wed, 03 Sep 2014 18:57:41 -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
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=AHCGESp+BSrVmYXAUWqGU9xO7ExhE83QJAMMbkPYuPo=;
        b=JHGjUYbJuTccLk880G4MR+Z2z3a9N2nAZ4J8ljXEGp+Td1/jFZ2y8OxWE/jt6OPGgD
         eQJeghdKOZ+cHu7OgYO+bF9ZgBgAGvr2IwM5EqshmQelVnHayT7dbwJ+q/KTEYh8Kpjq
         wKmlPdougpN1pkdJaefkPAi0fxk/SpzhVXM2yRc5mepoy9TaIWoHJQ2Fn1PYCjpnDktB
         Lqt644/ssXMq4shOiqhZpRVcyNAePx7pk/Oci50LL7Y75uIvyq+AYKu/HfwOn/hFeRpd
         CTANCGtc9y5fkdElQ0i6WL4XRRadFmx+jfT7zV9x3AcQvdtLpaQ2AqCUzxsSvQTYsE29
         RGuA==
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:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=AHCGESp+BSrVmYXAUWqGU9xO7ExhE83QJAMMbkPYuPo=;
        b=jMABUcTxOsy07AYrKJjLKshnSuMvcJ+/1zSF47daD65KVxcBNRMnFIgYqKlrMlPaFj
         yDHTLePJwP73tPb9NLyXcH17ycuZJxQiPmienVlnrV/wyiUDkmppAMqsCBjxjhbAP6se
         PgU3csQO3lOpO63+Xgo7v4b6V0lpbfX9qPlzp0+ATdYWaxqZpP58+gYGbYQm54vClnLm
         RA+vU/T3QIoPbPMD3/PKCFCa0m11fnmVmKNkliFEHHcKbAQan+WBzBk2YwCR9oSCfMJt
         p6nhKPn53NO5v53anLo+Xi0EmQMersxa1X3E5pJ+NkKsyqp8wLL+MwStuBG04PGTvCF2
         sHaQ==
X-Gm-Message-State: ALoCoQnX1ZSSPuXIoYVNLLDXSYXI746bWE+dhf1Ve8AtWfu0TcRiFXxVnplikyPyJSkOco7Dqy13
X-Received: by 10.42.16.69 with SMTP id o5mr795130ica.17.1409795861069;
        Wed, 03 Sep 2014 18:57:41 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.34.99 with SMTP id k90ls73014qgk.78.gmail; Wed, 03 Sep
 2014 18:57:40 -0700 (PDT)
X-Received: by 10.140.25.162 with SMTP id 31mr2685qgt.9.1409795860372;
        Wed, 03 Sep 2014 18:57:40 -0700 (PDT)
In-Reply-To: <CAGsORuB6Bz+vjD1ddNNJ6t5GBmdff3xKMe6HkY549=05gzjB9w@mail.gmail.com>
X-Original-Sender: fmatthew5876@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <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:12665
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/12665>

------=_Part_5088_1602156432.1409795859875
Content-Type: text/plain; charset=UTF-8

There was another discussion here about possibly inventing a new syntax for 
templating qualifiers (const, volatile, ref) but keeping the underlying 
type fixed. That's a much harder problem, but if solved it would also solve 
your problem here as well.

https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/oFglS6zn8ik


On Wednesday, September 3, 2014 3:16:06 PM UTC-4, Zhihao Yuan wrote:
>
> We know the difficulty of writing both const and non-const
> member functions, and one suggestion was made in this
> mailing list, which is to make const qualifier conditional
> like noexcept.  Meanwhile I have another idea which can
> be used to solve the problem, plus another issue I'm going
> to state below.
>
> Member function with reference qualifier does not benefit
> from reference collapsing.  To write a function doing perfect
> forwarding, you have to have a template argument T&&
>
>   template <typename T>
>   void f(T&& v);
>
> since reference collapsing requires template argument
> deduction, but member function has no such thing for *this.
>
> Actually, the natural of the problem of `const` is as same as
> this one.  If it's a free function,
>
>   template <typename T>
>   void f(T& v);
>
> will work for both Type& and Type const&, but we have no
> `T` for *this.
>
> So how about making the type of *this into a template?
> (I know, it's always lvalue, but I can't find a better term for
> now.)
>
>   template <this T>  // bikeshedding time
>   void f() T&;  // A& or A const&
>
>   template <this T>
>   void f() T&&;  // A& or A&&, etc
>
> Problem solved, AFAICS.
>
> One more thing, several months ago I found it's very annoying
> to write recursive member function with rvalue reference
> qualifier:
>
>   struct A {
>     void f() && {
>       f();  // does not compile
>       // try std::move(*this).f()
>     }
>   };
>
> Because the implicit (*this) is treated as a lvalue, even in
> a member function for rvalue.  With my suggestion you can
> write std::forward<T>(*this).f() but that's not my point...
> To implement my suggestion, you have to be able to
> distinguish the value category of *this, so why not redefine
> the "implicit this rule" in template *this function to to make
> the following code work?
>
>   template <this T>
>   void f() T&&
>   {
>     f();
>   }
>
> Comments are welcome.
>
> -- 
> Zhihao Yuan, ID lichray
> The best way to predict the future is to invent it.
> ___________________________________________________
> 4BSD -- http://bit.ly/blog4bsd 
>

-- 

--- 
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_5088_1602156432.1409795859875
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">There was another discussion here about possibly inventing=
 a new syntax for templating qualifiers (const, volatile, ref) but keeping =
the underlying type fixed. That's a much harder problem, but if solved it w=
ould also solve your problem here as well.<br><br>https://groups.google.com=
/a/isocpp.org/forum/#!topic/std-proposals/oFglS6zn8ik<div><br></div><div><b=
r>On Wednesday, September 3, 2014 3:16:06 PM UTC-4, Zhihao Yuan wrote:<bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div><div><di=
v><div><div><div><div><div>We know the difficulty of writing both const and=
 non-const<br></div><div>member functions, and one suggestion was made in t=
his<br>mailing list, which is to make const qualifier conditional<br>
</div><div>like noexcept.&nbsp; Meanwhile I have another idea which can<br>=
</div><div>be used to solve the problem, plus another issue I'm going<br>to=
 state below.<br><br></div><div>Member function with reference qualifier do=
es not benefit<br>
from reference collapsing.&nbsp; To write a function doing perfect<br>forwa=
rding, you have to have a template argument T&amp;&amp;<br><br></div><div>&=
nbsp; template &lt;typename T&gt;<br></div><div>&nbsp; void f(T&amp;&amp; v=
);<br></div>
<div><br></div><div>since reference collapsing requires template argument<b=
r>deduction, but member function has no such thing for *this.<br><br></div>=
<div>Actually, the natural of the problem of `const` is as same as<br>this =
one.&nbsp; If it's a free function,<br>
<br></div><div>&nbsp; template &lt;typename T&gt;<br></div><div>&nbsp; void=
 f(T&amp; v);<br><br></div><div>will work for both Type&amp; and Type const=
&amp;, but we have no<br></div><div>`T` for *this.<br><br></div><div>So how=
 about making the type of *this into a template?<br>
(I know, it's always lvalue, but I can't find a better term for<br>now.)<br=
><br></div><div>&nbsp; template &lt;this T&gt;&nbsp; // bikeshedding time<b=
r></div><div>&nbsp; void f() T&amp;;&nbsp; // A&amp; or A const&amp;<br></d=
iv><div>
<br>&nbsp; template &lt;this T&gt;<br></div><div>&nbsp; void f() T&amp;&amp=
;;&nbsp; // A&amp; or A&amp;&amp;, etc<br><br></div><div>Problem solved, AF=
AICS.<br><br></div><div>One more thing, several months ago I found it's ver=
y annoying<br>
to write recursive member function with rvalue reference<br>qualifier:<br><=
/div><br>&nbsp; struct A {<br>&nbsp; &nbsp; void f() &amp;&amp; {<br>&nbsp;=
 &nbsp; &nbsp; f();&nbsp; // does not compile<br></div><div>&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp; // try std::move(*this).f()<br></div><div>
&nbsp;&nbsp;&nbsp; }<br>&nbsp; };<br><br></div>Because the implicit (*this)=
 is treated as a lvalue, even in<br>a member function for rvalue.&nbsp; Wit=
h my suggestion you can<br></div>write std::forward&lt;T&gt;(*this).f() but=
 that's not my point...<br>
</div>To implement my suggestion, you have to be able to<br>distinguish the=
 value category of *this, so why not redefine<br></div>the "implicit this r=
ule" in template *this function to to make<br></div>the following code work=
?<br>
<br></div>&nbsp; template &lt;this T&gt;<br></div>&nbsp; void f() T&amp;&am=
p;<br>&nbsp; {<br></div>&nbsp;&nbsp;&nbsp; f();<br><div>&nbsp; }<br><br></d=
iv><div>Comments are welcome.<br clear=3D"all"></div><div><div><div><div><d=
iv><div><div><div><div><div><div>
<br>-- <br>Zhihao Yuan, ID lichray<br>The best way to predict the future is=
 to invent it.<br>______________________________<wbr>_____________________<=
br>4BSD -- <a href=3D"http://bit.ly/blog4bsd" target=3D"_blank" onmousedown=
=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fbit.ly%2Fblog4b=
sd\46sa\75D\46sntz\0751\46usg\75AFQjCNENWZA3DF1H_gEgIkwnCr7FAkiCyQ';return =
true;" onclick=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fb=
it.ly%2Fblog4bsd\46sa\75D\46sntz\0751\46usg\75AFQjCNENWZA3DF1H_gEgIkwnCr7FA=
kiCyQ';return true;">http://bit.ly/blog4bsd</a>
</div></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></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_5088_1602156432.1409795859875--

.
