Topic: Templated *this
Author: Zhihao Yuan <zy@miator.net>
Date: Wed, 3 Sep 2014 15:16:03 -0400
Raw View
--047d7bdc99aa2fedc405022e11e8
Content-Type: text/plain; charset=UTF-8
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/.
--047d7bdc99aa2fedc405022e11e8
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><div><div><div><div><div><div><div><div>We know the d=
ifficulty of writing both const and non-const<br></div><div>member function=
s, and one suggestion was made in this<br>mailing list, which is to make co=
nst qualifier conditional<br>
</div><div>like noexcept.=C2=A0 Meanwhile I have another idea which can<br>=
</div><div>be used to solve the problem, plus another issue I'm going<b=
r>to state below.<br><br></div><div>Member function with reference qualifie=
r does not benefit<br>
from reference collapsing.=C2=A0 To write a function doing perfect<br>forwa=
rding, you have to have a template argument T&&<br><br></div><div>=
=C2=A0 template <typename T><br></div><div>=C2=A0 void f(T&& =
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.=C2=A0 If it's a free function,<br>
<br></div><div>=C2=A0 template <typename T><br></div><div>=C2=A0 void=
f(T& v);<br><br></div><div>will work for both Type& and Type const=
&, 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>=C2=A0 template <this T>=C2=A0 // bikesheddin=
g time<br></div><div>=C2=A0 void f() T&;=C2=A0 // A& or A const&=
;<br></div><div>
<br>=C2=A0 template <this T><br></div><div>=C2=A0 void f() T&&=
;;=C2=A0 // A& or A&&, etc<br><br></div><div>Problem solved, AF=
AICS.<br><br></div><div>One more thing, several months ago I found it's=
very annoying<br>
to write recursive member function with rvalue reference<br>qualifier:<br><=
/div><br>=C2=A0 struct A {<br>=C2=A0 =C2=A0 void f() && {<br>=C2=A0=
=C2=A0 =C2=A0 f();=C2=A0 // does not compile<br></div><div>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 // try std::move(*this).f()<br></div><div>
=C2=A0=C2=A0=C2=A0 }<br>=C2=A0 };<br><br></div>Because the implicit (*this)=
is treated as a lvalue, even in<br>a member function for rvalue.=C2=A0 Wit=
h my suggestion you can<br></div>write std::forward<T>(*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 t=
his rule" in template *this function to to make<br></div>the following=
code work?<br>
<br></div>=C2=A0 template <this T><br></div>=C2=A0 void f() T&&am=
p;<br>=C2=A0 {<br></div>=C2=A0=C2=A0=C2=A0 f();<br><div>=C2=A0 }<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>___________________________________________________<br>4B=
SD -- <a href=3D"http://bit.ly/blog4bsd" target=3D"_blank">http://bit.ly/bl=
og4bsd</a>
</div></div></div></div></div></div></div></div></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 />
--047d7bdc99aa2fedc405022e11e8--
.
Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Wed, 3 Sep 2014 18:57:39 -0700 (PDT)
Raw View
------=_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. 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. To write a function doing perfect<br>forwa=
rding, you have to have a template argument T&&<br><br></div><div>&=
nbsp; template <typename T><br></div><div> void f(T&& 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. If it's a free function,<br>
<br></div><div> template <typename T><br></div><div> void=
f(T& v);<br><br></div><div>will work for both Type& and Type const=
&, 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> template <this T> // bikeshedding time<b=
r></div><div> void f() T&; // A& or A const&<br></d=
iv><div>
<br> template <this T><br></div><div> void f() T&&=
;; // A& or A&&, 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> struct A {<br> void f() && {<br> =
f(); // does not compile<br></div><div> &nb=
sp; // try std::move(*this).f()<br></div><div>
}<br> };<br><br></div>Because the implicit (*this)=
is treated as a lvalue, even in<br>a member function for rvalue. Wit=
h my suggestion you can<br></div>write std::forward<T>(*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> template <this T><br></div> void f() T&&am=
p;<br> {<br></div> f();<br><div> }<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" 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--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Wed, 3 Sep 2014 19:01:23 -0700
Raw View
--001a1133ee10c36e86050233ba8c
Content-Type: text/plain; charset=UTF-8
I made a suggestion in the original thread too:
https://groups.google.com/a/isocpp.org/d/msg/std-proposals/3RygF_VV098/yaxZizFg_SsJ
On Wed, Sep 3, 2014 at 6:57 PM, Matthew Fioravante <fmatthew5876@gmail.com>
wrote:
> 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/.
>
--
---
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/.
--001a1133ee10c36e86050233ba8c
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I made a suggestion in the original thread too:<br><div cl=
ass=3D"gmail_extra"><br></div><div class=3D"gmail_extra"><a href=3D"https:/=
/groups.google.com/a/isocpp.org/d/msg/std-proposals/3RygF_VV098/yaxZizFg_Ss=
J">https://groups.google.com/a/isocpp.org/d/msg/std-proposals/3RygF_VV098/y=
axZizFg_SsJ</a><br>
<br><div class=3D"gmail_quote">On Wed, Sep 3, 2014 at 6:57 PM, Matthew Fior=
avante <span dir=3D"ltr"><<a href=3D"mailto:fmatthew5876@gmail.com" targ=
et=3D"_blank">fmatthew5876@gmail.com</a>></span> wrote:<br><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1p=
x;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1=
ex">
<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 would also solve your problem here as well.<br>
<br><a href=3D"https://groups.google.com/a/isocpp.org/forum/#!topic/std-pro=
posals/oFglS6zn8ik" target=3D"_blank">https://groups.google.com/a/isocpp.or=
g/forum/#!topic/std-proposals/oFglS6zn8ik</a><div><div class=3D"h5"><div><b=
r>
</div><div><br>On Wednesday, September 3, 2014 3:16:06 PM UTC-4, Zhihao Yua=
n wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex=
;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style=
:solid;padding-left:1ex">
<div dir=3D"ltr"><div><div><div><div><div><div><div><div><div>We know the d=
ifficulty of writing both const and non-const<br></div><div>member function=
s, and one suggestion was made in this<br>mailing list, which is to make co=
nst qualifier conditional<br>
</div><div>like noexcept.=C2=A0 Meanwhile I have another idea which can<br>=
</div><div>be used to solve the problem, plus another issue I'm going<b=
r>to state below.<br><br></div><div>Member function with reference qualifie=
r does not benefit<br>
from reference collapsing.=C2=A0 To write a function doing perfect<br>forwa=
rding, you have to have a template argument T&&<br><br></div><div>=
=C2=A0 template <typename T><br></div><div>=C2=A0 void f(T&& =
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.=C2=A0 If it's a free function,<br>
<br></div><div>=C2=A0 template <typename T><br></div><div>=C2=A0 void=
f(T& v);<br><br></div><div>will work for both Type& and Type const=
&, 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>=C2=A0 template <this T>=C2=A0 // bikesheddin=
g time<br></div><div>=C2=A0 void f() T&;=C2=A0 // A& or A const&=
;<br></div><div>
<br>=C2=A0 template <this T><br></div><div>=C2=A0 void f() T&&=
;;=C2=A0 // A& or A&&, etc<br><br></div><div>Problem solved, AF=
AICS.<br><br></div><div>One more thing, several months ago I found it's=
very annoying<br>
to write recursive member function with rvalue reference<br>qualifier:<br><=
/div><br>=C2=A0 struct A {<br>=C2=A0 =C2=A0 void f() && {<br>=C2=A0=
=C2=A0 =C2=A0 f();=C2=A0 // does not compile<br></div><div>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 // try std::move(*this).f()<br></div><div>
=C2=A0=C2=A0=C2=A0 }<br>=C2=A0 };<br><br></div>Because the implicit (*this)=
is treated as a lvalue, even in<br>a member function for rvalue.=C2=A0 Wit=
h my suggestion you can<br></div>write std::forward<T>(*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 t=
his rule" in template *this function to to make<br></div>the following=
code work?<br>
<br></div>=C2=A0 template <this T><br></div>=C2=A0 void f() T&&am=
p;<br>=C2=A0 {<br></div>=C2=A0=C2=A0=C2=A0 f();<br><div>=C2=A0 }<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>______________________________<u></u>____________________=
_<br>4BSD -- <a href=3D"http://bit.ly/blog4bsd" target=3D"_blank">http://bi=
t.ly/blog4bsd</a>
</div></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></div></div></div></div><div class=3D""><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 />
--001a1133ee10c36e86050233ba8c--
.
Author: Zhihao Yuan <zy@miator.net>
Date: Wed, 3 Sep 2014 22:12:23 -0400
Raw View
--047d7b343a4c1b2091050233e20e
Content-Type: text/plain; charset=UTF-8
I saw that, but that is OK as a meta-programming, while I don't think the
problem of const and perfect forwarding member function should require user
to go that far. And, these two features can coexist.
On Sep 3, 2014 9:57 PM, "Matthew Fioravante" <fmatthew5876@gmail.com> wrote:
> 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/.
>
--
---
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/.
--047d7b343a4c1b2091050233e20e
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">I saw that, but that is OK as a meta-programming, while I do=
n't think the problem of const and perfect forwarding member function s=
hould require user to go that far.=C2=A0 And, these two features can coexis=
t.</p>
<div class=3D"gmail_quote">On Sep 3, 2014 9:57 PM, "Matthew Fioravante=
" <<a href=3D"mailto:fmatthew5876@gmail.com">fmatthew5876@gmail.com=
</a>> wrote:<br type=3D"attribution"><blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<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 would also solve your problem here as well.<br>
<br><a href=3D"https://groups.google.com/a/isocpp.org/forum/#!topic/std-pro=
posals/oFglS6zn8ik" target=3D"_blank">https://groups.google.com/a/isocpp.or=
g/forum/#!topic/std-proposals/oFglS6zn8ik</a><div><br></div><div><br>On Wed=
nesday, September 3, 2014 3:16:06 PM UTC-4, Zhihao Yuan wrote:<blockquote c=
lass=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #c=
cc solid;padding-left:1ex">
<div dir=3D"ltr"><div><div><div><div><div><div><div><div><div>We know the d=
ifficulty of writing both const and non-const<br></div><div>member function=
s, and one suggestion was made in this<br>mailing list, which is to make co=
nst qualifier conditional<br>
</div><div>like noexcept.=C2=A0 Meanwhile I have another idea which can<br>=
</div><div>be used to solve the problem, plus another issue I'm going<b=
r>to state below.<br><br></div><div>Member function with reference qualifie=
r does not benefit<br>
from reference collapsing.=C2=A0 To write a function doing perfect<br>forwa=
rding, you have to have a template argument T&&<br><br></div><div>=
=C2=A0 template <typename T><br></div><div>=C2=A0 void f(T&& =
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.=C2=A0 If it's a free function,<br>
<br></div><div>=C2=A0 template <typename T><br></div><div>=C2=A0 void=
f(T& v);<br><br></div><div>will work for both Type& and Type const=
&, 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>=C2=A0 template <this T>=C2=A0 // bikesheddin=
g time<br></div><div>=C2=A0 void f() T&;=C2=A0 // A& or A const&=
;<br></div><div>
<br>=C2=A0 template <this T><br></div><div>=C2=A0 void f() T&&=
;;=C2=A0 // A& or A&&, etc<br><br></div><div>Problem solved, AF=
AICS.<br><br></div><div>One more thing, several months ago I found it's=
very annoying<br>
to write recursive member function with rvalue reference<br>qualifier:<br><=
/div><br>=C2=A0 struct A {<br>=C2=A0 =C2=A0 void f() && {<br>=C2=A0=
=C2=A0 =C2=A0 f();=C2=A0 // does not compile<br></div><div>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 // try std::move(*this).f()<br></div><div>
=C2=A0=C2=A0=C2=A0 }<br>=C2=A0 };<br><br></div>Because the implicit (*this)=
is treated as a lvalue, even in<br>a member function for rvalue.=C2=A0 Wit=
h my suggestion you can<br></div>write std::forward<T>(*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 t=
his rule" in template *this function to to make<br></div>the following=
code work?<br>
<br></div>=C2=A0 template <this T><br></div>=C2=A0 void f() T&&am=
p;<br>=C2=A0 {<br></div>=C2=A0=C2=A0=C2=A0 f();<br><div>=C2=A0 }<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>______________________________<u></u>____________________=
_<br>4BSD -- <a href=3D"http://bit.ly/blog4bsd" target=3D"_blank">http://bi=
t.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" 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>
</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 />
--047d7b343a4c1b2091050233e20e--
.
Author: Zhihao Yuan <zy@miator.net>
Date: Wed, 3 Sep 2014 22:17:33 -0400
Raw View
--001a1136ad728e4e88050233f4ed
Content-Type: text/plain; charset=UTF-8
I missed this one.
I understand the current limitation of *this, but I'm arguing that we
should have a "new" *this which has a context dependent value category, so
that we can make simple things easy to do, by using a plain parameterized
type, as simple as a free function, instead of something more complex than
that, including template-templates.
On Sep 3, 2014 10:01 PM, "Richard Smith" <richard@metafoo.co.uk> wrote:
> I made a suggestion in the original thread too:
>
>
> https://groups.google.com/a/isocpp.org/d/msg/std-proposals/3RygF_VV098/yaxZizFg_SsJ
>
> On Wed, Sep 3, 2014 at 6:57 PM, Matthew Fioravante <fmatthew5876@gmail.com
> > wrote:
>
>> 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/.
>>
>
> --
>
> ---
> 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/.
>
--
---
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/.
--001a1136ad728e4e88050233f4ed
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr">I missed this one.</p>
<p dir=3D"ltr">I understand the current limitation of *this, but I'm ar=
guing that we should have a "new" *this which has a context depen=
dent value category, so that we can make simple things easy to do, by using=
a plain parameterized type, as simple as a free function, instead of somet=
hing more complex than that, including template-templates.</p>
<div class=3D"gmail_quote">On Sep 3, 2014 10:01 PM, "Richard Smith&quo=
t; <<a href=3D"mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>&g=
t; wrote:<br type=3D"attribution"><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir=3D"ltr">I made a suggestion in the original thread too:<br><div cl=
ass=3D"gmail_extra"><br></div><div class=3D"gmail_extra"><a href=3D"https:/=
/groups.google.com/a/isocpp.org/d/msg/std-proposals/3RygF_VV098/yaxZizFg_Ss=
J" target=3D"_blank">https://groups.google.com/a/isocpp.org/d/msg/std-propo=
sals/3RygF_VV098/yaxZizFg_SsJ</a><br>
<br><div class=3D"gmail_quote">On Wed, Sep 3, 2014 at 6:57 PM, Matthew Fior=
avante <span dir=3D"ltr"><<a href=3D"mailto:fmatthew5876@gmail.com" targ=
et=3D"_blank">fmatthew5876@gmail.com</a>></span> wrote:<br><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1p=
x;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1=
ex">
<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 would also solve your problem here as well.<br>
<br><a href=3D"https://groups.google.com/a/isocpp.org/forum/#!topic/std-pro=
posals/oFglS6zn8ik" target=3D"_blank">https://groups.google.com/a/isocpp.or=
g/forum/#!topic/std-proposals/oFglS6zn8ik</a><div><div><div><br>
</div><div><br>On Wednesday, September 3, 2014 3:16:06 PM UTC-4, Zhihao Yua=
n wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex=
;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style=
:solid;padding-left:1ex">
<div dir=3D"ltr"><div><div><div><div><div><div><div><div><div>We know the d=
ifficulty of writing both const and non-const<br></div><div>member function=
s, and one suggestion was made in this<br>mailing list, which is to make co=
nst qualifier conditional<br>
</div><div>like noexcept.=C2=A0 Meanwhile I have another idea which can<br>=
</div><div>be used to solve the problem, plus another issue I'm going<b=
r>to state below.<br><br></div><div>Member function with reference qualifie=
r does not benefit<br>
from reference collapsing.=C2=A0 To write a function doing perfect<br>forwa=
rding, you have to have a template argument T&&<br><br></div><div>=
=C2=A0 template <typename T><br></div><div>=C2=A0 void f(T&& =
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.=C2=A0 If it's a free function,<br>
<br></div><div>=C2=A0 template <typename T><br></div><div>=C2=A0 void=
f(T& v);<br><br></div><div>will work for both Type& and Type const=
&, 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>=C2=A0 template <this T>=C2=A0 // bikesheddin=
g time<br></div><div>=C2=A0 void f() T&;=C2=A0 // A& or A const&=
;<br></div><div>
<br>=C2=A0 template <this T><br></div><div>=C2=A0 void f() T&&=
;;=C2=A0 // A& or A&&, etc<br><br></div><div>Problem solved, AF=
AICS.<br><br></div><div>One more thing, several months ago I found it's=
very annoying<br>
to write recursive member function with rvalue reference<br>qualifier:<br><=
/div><br>=C2=A0 struct A {<br>=C2=A0 =C2=A0 void f() && {<br>=C2=A0=
=C2=A0 =C2=A0 f();=C2=A0 // does not compile<br></div><div>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 // try std::move(*this).f()<br></div><div>
=C2=A0=C2=A0=C2=A0 }<br>=C2=A0 };<br><br></div>Because the implicit (*this)=
is treated as a lvalue, even in<br>a member function for rvalue.=C2=A0 Wit=
h my suggestion you can<br></div>write std::forward<T>(*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 t=
his rule" in template *this function to to make<br></div>the following=
code work?<br>
<br></div>=C2=A0 template <this T><br></div>=C2=A0 void f() T&&am=
p;<br>=C2=A0 {<br></div>=C2=A0=C2=A0=C2=A0 f();<br><div>=C2=A0 }<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>______________________________<u></u>____________________=
_<br>4BSD -- <a href=3D"http://bit.ly/blog4bsd" target=3D"_blank">http://bi=
t.ly/blog4bsd</a>
</div></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></div></div></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" 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" 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>
</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 />
--001a1136ad728e4e88050233f4ed--
.