Topic: Return this or *this in overridden method in


Author: Phil Miller <unmobile@gmail.com>
Date: Fri, 30 Nov 2018 07:48:50 -0600
Raw View
--000000000000db7bba057be20fc2
Content-Type: text/plain; charset="UTF-8"

I believe you could accomplish what you want with CRTP. Template the base
class over its child class type, and have the base class method return a
reference to that child type. Without having tried it, I think you may need
to add a hidden extra base-of-base class to make it work, but that may be
avoided.

On Fri, Nov 30, 2018, 7:38 AM Vu Pham <phvu225@gmail.com wrote:

> While thinking about my (ahem) streaming proposal
> <https://groups.google.com/a/isocpp.org/forum/?utm_medium=email&utm_source=footer#!msg/std-proposals/w0j1pF8gQPQ/YzHdodLoBwAJ>,
> I think I found a missing feature in C++. Since this group is highly
> populated with people speaking C++ fluently, I will ask this here instead.
>
> Assume I have the following classes:
>
> class A {
> public:
>     A& f1(float& x) {
>         x++;
>         return *this;
>     }
> };
>
> class B: public A {
> public:
>     B& f2(float& x) {
>         x--;
>         return *this;
>     }
> };
>
> int main()
> {
>     float x(100.0f);
>     B b;
>     *static_cast<B>(b.f1(x)).f2(x);*   // this doesn't compile
>     return 0;
> }
>
> The idea is I want B::f1() to return an instance of B (it should, given
> the implementation of f1), but since the return type of f1() is A&,
> apparently there is no way to make it work the way I want. Here are a few
> alternatives I tried:
>
> - Make f1() returns A*, then cast the returned pointer. This doesn't look
> really nice.
> - Change the return type of f1() to something like decltype(*this) or
> auto, none of this seems to work.
>
> This issue may get worse if A and B are templated, or in a more
> complicated scenario where A::f1() returns a child class C of A, while B is
> a child of A but not C, and I want to override B::f1() to return D, which
> is a child class of B.
>
> Since C++ allows multiple inheritence, and in the same light with the
> *concept* idea that are coming up in new C++, should we coin a new
> annotation to indicate that a function returns an instance of *this*
> class? The actual returned type will change depending on the actual type of
> the class that mix those functions in.
>
> What do you think?
> Vu
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFhKpXFOV9DSmmrC3HdGF7Fr44fRzpq%3Dn2JTkUcHHE6Qbux-PA%40mail.gmail.com
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFhKpXFOV9DSmmrC3HdGF7Fr44fRzpq%3Dn2JTkUcHHE6Qbux-PA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAMDbWJH0JuEzBgDrbRVd6jxNtQ2FMX377iJRuyuRFT3tos93iA%40mail.gmail.com.

--000000000000db7bba057be20fc2
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">I believe you could accomplish what you want with CRTP. T=
emplate the base class over its child class type, and have the base class m=
ethod return a reference to that child type. Without having tried it, I thi=
nk you may need to add a hidden extra base-of-base class to make it work, b=
ut that may be avoided.</div><br><div class=3D"gmail_quote"><div dir=3D"ltr=
">On Fri, Nov 30, 2018, 7:38 AM Vu Pham &lt;<a href=3D"mailto:phvu225@gmail=
..com">phvu225@gmail.com</a> wrote:<br></div><blockquote class=3D"gmail_quot=
e" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">=
<div dir=3D"ltr"><div dir=3D"ltr"><div>While thinking about my (ahem) <a hr=
ef=3D"https://groups.google.com/a/isocpp.org/forum/?utm_medium=3Demail&amp;=
utm_source=3Dfooter#!msg/std-proposals/w0j1pF8gQPQ/YzHdodLoBwAJ" target=3D"=
_blank" rel=3D"noreferrer">streaming proposal</a>, I think I found a missin=
g feature in C++. Since this group is highly populated with people speaking=
 C++ fluently, I will ask this here instead.</div><div><br></div><div>Assum=
e I have the following classes:</div><div><br></div><div><span style=3D"fon=
t-family:monospace,monospace">class A {<br>public:<br>=C2=A0=C2=A0=C2=A0 A&=
amp; f1(float&amp; x) {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 x++;<=
br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return *this;<br>=C2=A0=C2=A0=
=C2=A0 }<br>};<br><br>class B: public A {<br>public:<br>=C2=A0=C2=A0=C2=A0 =
B&amp; f2(float&amp; x) {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 x--=
;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return *this;<br>=C2=A0=C2=
=A0=C2=A0 }<br>};<br><br>int main()<br>{<br>=C2=A0=C2=A0=C2=A0 float x(100.=
0f);<br>=C2=A0=C2=A0=C2=A0 B b;<br>=C2=A0=C2=A0=C2=A0 <b>static_cast&lt;B&g=
t;(b.f1(x)).f2(x);</b>=C2=A0=C2=A0 // this doesn&#39;t compile<br>=C2=A0=C2=
=A0=C2=A0 return 0;<br>}</span><br></div><div><br></div><div>The idea is I =
want B::f1() to return an instance of B (it should, given the implementatio=
n of f1), but since the return type of f1() is A&amp;, apparently there is =
no way to make it work the way I want. Here are a few alternatives I tried:=
</div><div><br></div><div>- Make f1() returns A*, then cast the returned po=
inter. This doesn&#39;t look really nice.</div><div>- Change the return typ=
e of f1() to something like decltype(*this) or auto, none of this seems to =
work.</div><div><br></div><div>This issue may get worse if A and B are temp=
lated, or in a more complicated scenario where A::f1() returns a child clas=
s C of A, while B is a child of A but not C, and I want to override B::f1()=
 to return D, which is a child class of B.</div><div><br></div><div>Since C=
++ allows multiple inheritence, and in the same light with the <i>concept</=
i> idea that are coming up in new C++, should we coin a new annotation to i=
ndicate that a function returns an instance of <i>this</i> class? The actua=
l returned type will change depending on the actual type of the class that =
mix those functions in.</div><div><br></div><div>What do you think?</div><d=
iv>Vu<br></div></div></div>

<p></p>

-- <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" target=3D"_=
blank" rel=3D"noreferrer">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" rel=3D"noreferrer">std-proposals@isocpp.org</a>.<br=
>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAFhKpXFOV9DSmmrC3HdGF7Fr44fRzpq%3Dn2=
JTkUcHHE6Qbux-PA%40mail.gmail.com?utm_medium=3Demail&amp;utm_source=3Dfoote=
r" target=3D"_blank" rel=3D"noreferrer">https://groups.google.com/a/isocpp.=
org/d/msgid/std-proposals/CAFhKpXFOV9DSmmrC3HdGF7Fr44fRzpq%3Dn2JTkUcHHE6Qbu=
x-PA%40mail.gmail.com</a>.<br>
</blockquote></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAMDbWJH0JuEzBgDrbRVd6jxNtQ2FMX377iJR=
uyuRFT3tos93iA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAMDbWJH0JuEzBgDr=
bRVd6jxNtQ2FMX377iJRuyuRFT3tos93iA%40mail.gmail.com</a>.<br />

--000000000000db7bba057be20fc2--

.


Author: =?UTF-8?Q?Micha=C5=82_Gawron?= <mcvsama@gmail.com>
Date: Fri, 30 Nov 2018 15:10:15 +0100
Raw View
Vu, I wonder what you mean by saying "an instance", is that a separate
object (a copy) or a reference? In this concrete example, change
static_cast to B& instead of B, it will compile and work.
Of course it's far from ideal when you have to static_cast to derived class=
es.
pt., 30 lis 2018 o 14:49 Phil Miller <unmobile@gmail.com> napisa=C5=82(a):
>
> I believe you could accomplish what you want with CRTP. Template the base=
 class over its child class type, and have the base class method return a r=
eference to that child type. Without having tried it, I think you may need =
to add a hidden extra base-of-base class to make it work, but that may be a=
voided.
>
> On Fri, Nov 30, 2018, 7:38 AM Vu Pham <phvu225@gmail.com wrote:
>>
>> While thinking about my (ahem) streaming proposal, I think I found a mis=
sing feature in C++. Since this group is highly populated with people speak=
ing C++ fluently, I will ask this here instead.
>>
>> Assume I have the following classes:
>>
>> class A {
>> public:
>>     A& f1(float& x) {
>>         x++;
>>         return *this;
>>     }
>> };
>>
>> class B: public A {
>> public:
>>     B& f2(float& x) {
>>         x--;
>>         return *this;
>>     }
>> };
>>
>> int main()
>> {
>>     float x(100.0f);
>>     B b;
>>     static_cast<B>(b.f1(x)).f2(x);   // this doesn't compile
>>     return 0;
>> }
>>
>> The idea is I want B::f1() to return an instance of B (it should, given =
the implementation of f1), but since the return type of f1() is A&, apparen=
tly there is no way to make it work the way I want. Here are a few alternat=
ives I tried:
>>
>> - Make f1() returns A*, then cast the returned pointer. This doesn't loo=
k really nice.
>> - Change the return type of f1() to something like decltype(*this) or au=
to, none of this seems to work.
>>
>> This issue may get worse if A and B are templated, or in a more complica=
ted scenario where A::f1() returns a child class C of A, while B is a child=
 of A but not C, and I want to override B::f1() to return D, which is a chi=
ld class of B.
>>
>> Since C++ allows multiple inheritence, and in the same light with the co=
ncept idea that are coming up in new C++, should we coin a new annotation t=
o indicate that a function returns an instance of this class? The actual re=
turned type will change depending on the actual type of the class that mix =
those functions in.
>>
>> What do you think?
>> Vu
>>
>> --
>> You received this message because you are subscribed to the Google Group=
s "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n email to std-proposals+unsubscribe@isocpp.org.
>> To post to this group, send email to std-proposals@isocpp.org.
>> To view this discussion on the web visit https://groups.google.com/a/iso=
cpp.org/d/msgid/std-proposals/CAFhKpXFOV9DSmmrC3HdGF7Fr44fRzpq%3Dn2JTkUcHHE=
6Qbux-PA%40mail.gmail.com.
>
> --
> 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.
> To view this discussion on the web visit https://groups.google.com/a/isoc=
pp.org/d/msgid/std-proposals/CAMDbWJH0JuEzBgDrbRVd6jxNtQ2FMX377iJRuyuRFT3to=
s93iA%40mail.gmail.com.

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAB%2BhmstdjiuT7Z8%2B_pyRjCNZJ4p7o7gyHD%2BKhB8yY=
RuZEiKRUA%40mail.gmail.com.

.


Author: =?UTF-8?Q?=27Thomas_K=C3=B6ppe=27_via_ISO_C=2B=2B_Standard_=2D_Future_Proposals?= <std-proposals@isocpp.org>
Date: Fri, 30 Nov 2018 06:22:21 -0800 (PST)
Raw View
------=_Part_3364_326254096.1543587741999
Content-Type: multipart/alternative;
 boundary="----=_Part_3365_442052914.1543587742000"

------=_Part_3365_442052914.1543587742000
Content-Type: text/plain; charset="UTF-8"

On Friday, 30 November 2018 13:38:20 UTC, Vu Pham wrote:
>
>     float x(100.0f);
>     B b;
>     *static_cast<B>(b.f1(x)).f2(x);*   // this doesn't compile
>

Shouldn't this say *static_cast<B&>(b.f1(x)).f2(x))?*

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/c692ab9e-5b02-4482-b242-227c02ffc21d%40isocpp.org.

------=_Part_3365_442052914.1543587742000
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Friday, 30 November 2018 13:38:20 UTC, Vu Pham  wrote:<=
blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bord=
er-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div dir=3D"lt=
r"><div><span style=3D"font-family: monospace, monospace;">=C2=A0 =C2=A0 fl=
oat x(100.0f);</span><br></div><div><span style=3D"font-family:monospace,mo=
nospace">=C2=A0=C2=A0=C2=A0 B b;<br>=C2=A0=C2=A0=C2=A0 <b>static_cast&lt;<f=
ont color=3D"#990000">B</font>&gt;(b.f1(x)).f2(x);</b><wbr>=C2=A0=C2=A0 // =
this doesn&#39;t compile</span></div></div></div></blockquote><div><br></di=
v><div>Shouldn&#39;t this say <b style=3D"font-family: monospace, monospace=
;">static_cast&lt;<font color=3D"#38761d">B&amp;</font>&gt;(b.f1(x)).f2(x))=
?</b></div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/c692ab9e-5b02-4482-b242-227c02ffc21d%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/c692ab9e-5b02-4482-b242-227c02ffc21d=
%40isocpp.org</a>.<br />

------=_Part_3365_442052914.1543587742000--

------=_Part_3364_326254096.1543587741999--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Fri, 30 Nov 2018 16:25:38 +0200
Raw View
On Fri, 30 Nov 2018 at 16:22, 'Thomas K=C3=B6ppe' via ISO C++ Standard -
Future Proposals <std-proposals@isocpp.org> wrote:
>
> On Friday, 30 November 2018 13:38:20 UTC, Vu Pham wrote:
>>
>>     float x(100.0f);
>>     B b;
>>     static_cast<B>(b.f1(x)).f2(x);   // this doesn't compile
>
>
> Shouldn't this say static_cast<B&>(b.f1(x)).f2(x))?

Yes. That makes it compile. A downcast of references/pointers is a
hierarchy cast, but when its target is a new object, it's
no longer a hierarchy cast.

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAFk2RUaAnCRn66P4mkZYaiN0AMWLX2V46KtWZQ0S3C2mJij=
_sQ%40mail.gmail.com.

.


Author: Vu Pham <phvu225@gmail.com>
Date: Fri, 30 Nov 2018 14:50:13 +0000
Raw View
--0000000000005869ec057be2eb00
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Yes, you're right, it should be B&. The example was oversimplified, here is
a better one:

class A {
public:
    A& f1(float& x);
};

class C: public A { };

class B: public A {
public:
    A& f1(float& x);
    B& f2(float& x);
};

class D: public B { };

A& A::f1(float& x) {
    x++;
    C c;
    return c;
}

A& B::f1(float& x) {
    x +=3D 2;
    D d;
    return d;
}

B& B::f2(float& x) {
    x--;
    return *this;
}

int main()
{
    float x(100.0f);
    B b;
    static_cast<D&>(b.f1(x)).f2(x);
    return 0;
}


This often comes up when we have 2 families of hierarchy, but one family is
descendent of the other. For example, assume we have a hierarchy of
collection types.
The parent class is Seq, with child classes Array, List. Then we want to
have a parallel version of the whole family, then we make ParSeq a child
class of Seq (with overriden methods), then ParArray, ParList child classes
of ParSeq...
It still feels awkward casting things all over again, including in CRTP.

I think I saw CRTP once. Man...
https://media0.giphy.com/media/11CXAq0P8h50GI/giphy.gif?cid=3D3640f6095c014=
84b4e314375497147b0



On Fri, Nov 30, 2018 at 2:25 PM Ville Voutilainen <
ville.voutilainen@gmail.com> wrote:

> On Fri, 30 Nov 2018 at 16:22, 'Thomas K=C3=B6ppe' via ISO C++ Standard -
> Future Proposals <std-proposals@isocpp.org> wrote:
> >
> > On Friday, 30 November 2018 13:38:20 UTC, Vu Pham wrote:
> >>
> >>     float x(100.0f);
> >>     B b;
> >>     static_cast<B>(b.f1(x)).f2(x);   // this doesn't compile
> >
> >
> > Shouldn't this say static_cast<B&>(b.f1(x)).f2(x))?
>
> Yes. That makes it compile. A downcast of references/pointers is a
> hierarchy cast, but when its target is a new object, it's
> no longer a hierarchy cast.
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFk2RUaAnCR=
n66P4mkZYaiN0AMWLX2V46KtWZQ0S3C2mJij_sQ%40mail.gmail.com
> .
>


--=20
PHAM Hoai Vu
LinkedIn: linkedin.com/in/vuphoai

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAFhKpXGTfjz9RA8t2en%2BEGTxP_WZjfG_tbYD5i3B%2BRQ=
vobAB9Q%40mail.gmail.com.

--0000000000005869ec057be2eb00
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div>Yes, you&#39;re rig=
ht, it should be B&amp;. The example was oversimplified, here is a better o=
ne:</div><div><span style=3D"font-family:monospace,monospace"><br></span></=
div><div><span style=3D"font-family:monospace,monospace">class A {<br>publi=
c:<br>=C2=A0=C2=A0=C2=A0 A&amp; f1(float&amp; x);<br>};<br><br>class C: pub=
lic A { };<br><br>class B: public A {<br>public:<br>=C2=A0=C2=A0=C2=A0 A&am=
p; f1(float&amp; x);<br>=C2=A0=C2=A0=C2=A0 B&amp; f2(float&amp; x);<br>};<b=
r><br>class D: public B { };<br><br>A&amp; A::f1(float&amp; x) {<br>=C2=A0=
=C2=A0=C2=A0 x++;<br>=C2=A0=C2=A0=C2=A0 C c;<br>=C2=A0=C2=A0=C2=A0 return c=
;<br>}<br><br>A&amp; B::f1(float&amp; x) {<br>=C2=A0=C2=A0=C2=A0 x +=3D 2;<=
br>=C2=A0=C2=A0=C2=A0 D d;<br>=C2=A0=C2=A0=C2=A0 return d;<br>}<br><br>B&am=
p; B::f2(float&amp; x) {<br>=C2=A0=C2=A0=C2=A0 x--;<br>=C2=A0=C2=A0=C2=A0 r=
eturn *this;<br>}<br>=C2=A0=C2=A0=C2=A0 <br>int main()<br>{<br>=C2=A0=C2=A0=
=C2=A0 float x(100.0f);<br>=C2=A0=C2=A0=C2=A0 B b;<br>=C2=A0=C2=A0=C2=A0 st=
atic_cast&lt;D&amp;&gt;(b.f1(x)).f2(x);<br>=C2=A0=C2=A0=C2=A0 return 0;<br>=
}</span></div><div><br></div><div><br></div><div>This often comes up when w=
e have 2 families of hierarchy, but one family is descendent of the other. =
For example, assume we have a hierarchy of collection types.</div><div>The =
parent class is Seq, with child classes Array, List. Then we want to have a=
 parallel version of the whole family, then we make ParSeq a child class of=
 Seq (with overriden methods), then ParArray, ParList child classes of ParS=
eq...</div><div>It still feels awkward casting things all over again, inclu=
ding in CRTP.<br></div><div><br></div><div>I think I saw CRTP once. Man...<=
br></div><div></div><div><a href=3D"https://media0.giphy.com/media/11CXAq0P=
8h50GI/giphy.gif?cid=3D3640f6095c01484b4e314375497147b0">https://media0.gip=
hy.com/media/11CXAq0P8h50GI/giphy.gif?cid=3D3640f6095c01484b4e314375497147b=
0</a></div><div><br></div><div><br></div></div></div></div><br><div class=
=3D"gmail_quote"><div dir=3D"ltr">On Fri, Nov 30, 2018 at 2:25 PM Ville Vou=
tilainen &lt;<a href=3D"mailto:ville.voutilainen@gmail.com">ville.voutilain=
en@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri,=
 30 Nov 2018 at 16:22, &#39;Thomas K=C3=B6ppe&#39; via ISO C++ Standard -<b=
r>
Future Proposals &lt;<a href=3D"mailto:std-proposals@isocpp.org" target=3D"=
_blank">std-proposals@isocpp.org</a>&gt; wrote:<br>
&gt;<br>
&gt; On Friday, 30 November 2018 13:38:20 UTC, Vu Pham wrote:<br>
&gt;&gt;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0float x(100.0f);<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0B b;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0static_cast&lt;B&gt;(b.f1(x)).f2(x);=C2=A0 =C2=
=A0// this doesn&#39;t compile<br>
&gt;<br>
&gt;<br>
&gt; Shouldn&#39;t this say static_cast&lt;B&amp;&gt;(b.f1(x)).f2(x))?<br>
<br>
Yes. That makes it compile. A downcast of references/pointers is a<br>
hierarchy cast, but when its target is a new object, it&#39;s<br>
no longer a hierarchy cast.<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%2Bunsubscribe@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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAFk2RUaAnCRn66P4mkZYaiN0AMWLX2V46KtW=
ZQ0S3C2mJij_sQ%40mail.gmail.com" rel=3D"noreferrer" target=3D"_blank">https=
://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFk2RUaAnCRn66P4mk=
ZYaiN0AMWLX2V46KtWZQ0S3C2mJij_sQ%40mail.gmail.com</a>.<br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr"><div><d=
iv dir=3D"ltr"><div>PHAM Hoai Vu</div><div>LinkedIn:=C2=A0<a href=3D"http:/=
/linkedin.com/in/vuphoai" target=3D"_blank">linkedin.com/in/vuphoai</a></di=
v></div></div></div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAFhKpXGTfjz9RA8t2en%2BEGTxP_WZjfG_tb=
YD5i3B%2BRQvobAB9Q%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFhKpXGTfjz9=
RA8t2en%2BEGTxP_WZjfG_tbYD5i3B%2BRQvobAB9Q%40mail.gmail.com</a>.<br />

--0000000000005869ec057be2eb00--

.


Author: Tony V E <tvaneerd@gmail.com>
Date: Fri, 30 Nov 2018 10:45:42 -0500
Raw View
<html><head></head><body lang=3D"en-US" style=3D"background-color: rgb(255,=
 255, 255); line-height: initial;">                                        =
                                              <div style=3D"width: 100%; fo=
nt-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif=
; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, =
255, 255);">You are returning references to stack objects when you return C=
 and D. That's undefined behavior. The object is destroyed, then you return=
 a reference to it.</div>                                                  =
                                                                           =
        <div style=3D"width: 100%; font-size: initial; font-family: Calibri=
, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align:=
 initial; background-color: rgb(255, 255, 255);"><br style=3D"display:initi=
al"></div>                                                                 =
                                                                           =
                                                       <div style=3D"font-s=
ize: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; co=
lor: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255,=
 255);">Sent&nbsp;from&nbsp;my&nbsp;BlackBerry&nbsp;portable&nbsp;Babbage&n=
bsp;Device</div>                                                           =
                                                                           =
                                            <table width=3D"100%" style=3D"=
background-color:white;border-spacing:0px;"> <tbody><tr><td colspan=3D"2" s=
tyle=3D"font-size: initial; text-align: initial; background-color: rgb(255,=
 255, 255);">                           <div style=3D"border-style: solid n=
one none; border-top-color: rgb(181, 196, 223); border-top-width: 1pt; padd=
ing: 3pt 0in 0in; font-family: Tahoma, 'BB Alpha Sans', 'Slate Pro'; font-s=
ize: 10pt;">  <div><b>From: </b>Vu Pham</div><div><b>Sent: </b>Friday, Nove=
mber 30, 2018 9:50 AM</div><div><b>To: </b>std-proposals@isocpp.org</div><d=
iv><b>Reply To: </b>std-proposals@isocpp.org</div><div><b>Subject: </b>Re: =
[std-proposals] Re: Return this or *this in overridden method in child clas=
s?</div></div></td></tr></tbody></table><div style=3D"border-style: solid n=
one none; border-top-color: rgb(186, 188, 209); border-top-width: 1pt; font=
-size: initial; text-align: initial; background-color: rgb(255, 255, 255);"=
></div><br><div id=3D"_originalContent" style=3D""><div dir=3D"ltr"><div di=
r=3D"ltr"><div dir=3D"ltr"><div>Yes, you're right, it should be B&amp;. The=
 example was oversimplified, here is a better one:</div><div><span style=3D=
"font-family:monospace,monospace"><br></span></div><div><span style=3D"font=
-family:monospace,monospace">class A {<br>public:<br>&nbsp;&nbsp;&nbsp; A&a=
mp; f1(float&amp; x);<br>};<br><br>class C: public A { };<br><br>class B: p=
ublic A {<br>public:<br>&nbsp;&nbsp;&nbsp; A&amp; f1(float&amp; x);<br>&nbs=
p;&nbsp;&nbsp; B&amp; f2(float&amp; x);<br>};<br><br>class D: public B { };=
<br><br>A&amp; A::f1(float&amp; x) {<br>&nbsp;&nbsp;&nbsp; x++;<br>&nbsp;&n=
bsp;&nbsp; C c;<br>&nbsp;&nbsp;&nbsp; return c;<br>}<br><br>A&amp; B::f1(fl=
oat&amp; x) {<br>&nbsp;&nbsp;&nbsp; x +=3D 2;<br>&nbsp;&nbsp;&nbsp; D d;<br=
>&nbsp;&nbsp;&nbsp; return d;<br>}<br><br>B&amp; B::f2(float&amp; x) {<br>&=
nbsp;&nbsp;&nbsp; x--;<br>&nbsp;&nbsp;&nbsp; return *this;<br>}<br>&nbsp;&n=
bsp;&nbsp; <br>int main()<br>{<br>&nbsp;&nbsp;&nbsp; float x(100.0f);<br>&n=
bsp;&nbsp;&nbsp; B b;<br>&nbsp;&nbsp;&nbsp; static_cast&lt;D&amp;&gt;(b.f1(=
x)).f2(x);<br>&nbsp;&nbsp;&nbsp; return 0;<br>}</span></div><div><br></div>=
<div><br></div><div>This often comes up when we have 2 families of hierarch=
y, but one family is descendent of the other. For example, assume we have a=
 hierarchy of collection types.</div><div>The parent class is Seq, with chi=
ld classes Array, List. Then we want to have a parallel version of the whol=
e family, then we make ParSeq a child class of Seq (with overriden methods)=
, then ParArray, ParList child classes of ParSeq...</div><div>It still feel=
s awkward casting things all over again, including in CRTP.<br></div><div><=
br></div><div>I think I saw CRTP once. Man...<br></div><div></div><div><a h=
ref=3D"https://media0.giphy.com/media/11CXAq0P8h50GI/giphy.gif?cid=3D3640f6=
095c01484b4e314375497147b0">https://media0.giphy.com/media/11CXAq0P8h50GI/g=
iphy.gif?cid=3D3640f6095c01484b4e314375497147b0</a></div><div><br></div><di=
v><br></div></div></div></div><br><div class=3D"gmail_quote"><div dir=3D"lt=
r">On Fri, Nov 30, 2018 at 2:25 PM Ville Voutilainen &lt;<a href=3D"mailto:=
ville.voutilainen@gmail.com">ville.voutilainen@gmail.com</a>&gt; wrote:<br>=
</div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-l=
eft:1px #ccc solid;padding-left:1ex">On Fri, 30 Nov 2018 at 16:22, 'Thomas =
K=C3=B6ppe' via ISO C++ Standard -<br>
Future Proposals &lt;<a href=3D"mailto:std-proposals@isocpp.org" target=3D"=
_blank">std-proposals@isocpp.org</a>&gt; wrote:<br>
&gt;<br>
&gt; On Friday, 30 November 2018 13:38:20 UTC, Vu Pham wrote:<br>
&gt;&gt;<br>
&gt;&gt;&nbsp; &nbsp; &nbsp;float x(100.0f);<br>
&gt;&gt;&nbsp; &nbsp; &nbsp;B b;<br>
&gt;&gt;&nbsp; &nbsp; &nbsp;static_cast&lt;B&gt;(b.f1(x)).f2(x);&nbsp; &nbs=
p;// this doesn't compile<br>
&gt;<br>
&gt;<br>
&gt; Shouldn't this say static_cast&lt;B&amp;&gt;(b.f1(x)).f2(x))?<br>
<br>
Yes. That makes it compile. A downcast of references/pointers is a<br>
hierarchy cast, but when its target is a new object, it's<br>
no longer a hierarchy cast.<br>
<br>
-- <br>
You received this message because you are subscribed to the Google Groups "=
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%2Bunsubscribe@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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAFk2RUaAnCRn66P4mkZYaiN0AMWLX2V46KtW=
ZQ0S3C2mJij_sQ%40mail.gmail.com" rel=3D"noreferrer" target=3D"_blank">https=
://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFk2RUaAnCRn66P4mk=
ZYaiN0AMWLX2V46KtWZQ0S3C2mJij_sQ%40mail.gmail.com</a>.<br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr"><div><d=
iv dir=3D"ltr"><div>PHAM Hoai Vu</div><div>LinkedIn:&nbsp;<a href=3D"http:/=
/linkedin.com/in/vuphoai" target=3D"_blank">linkedin.com/in/vuphoai</a></di=
v></div></div></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups "=
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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAFhKpXGTfjz9RA8t2en%2BEGTxP_WZjfG_tb=
YD5i3B%2BRQvobAB9Q%40mail.gmail.com?utm_medium=3Demail&amp;utm_source=3Dfoo=
ter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFhKpXGT=
fjz9RA8t2en%2BEGTxP_WZjfG_tbYD5i3B%2BRQvobAB9Q%40mail.gmail.com</a>.<br>
<br><!--end of _originalContent --></div></body></html>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/20181130154542.5181497.55947.67133%40=
gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com=
/a/isocpp.org/d/msgid/std-proposals/20181130154542.5181497.55947.67133%40gm=
ail.com</a>.<br />

.


Author: Vu Pham <phvu225@gmail.com>
Date: Fri, 30 Nov 2018 16:38:13 +0000
Raw View
--000000000000a9cca2057be46dbb
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

It is knowingly hard to do anything simple in C++. I guess it will make
everything easier if we just pretend all those lvalue references to be
pointers.

On Fri, Nov 30, 2018 at 3:45 PM Tony V E <tvaneerd@gmail.com> wrote:

> You are returning references to stack objects when you return C and D.
> That's undefined behavior. The object is destroyed, then you return a
> reference to it.
>
> Sent from my BlackBerry portable Babbage Device
> *From: *Vu Pham
> *Sent: *Friday, November 30, 2018 9:50 AM
> *To: *std-proposals@isocpp.org
> *Reply To: *std-proposals@isocpp.org
> *Subject: *Re: [std-proposals] Re: Return this or *this in overridden
> method in child class?
>
> Yes, you're right, it should be B&. The example was oversimplified, here
> is a better one:
>
> class A {
> public:
>     A& f1(float& x);
> };
>
> class C: public A { };
>
> class B: public A {
> public:
>     A& f1(float& x);
>     B& f2(float& x);
> };
>
> class D: public B { };
>
> A& A::f1(float& x) {
>     x++;
>     C c;
>     return c;
> }
>
> A& B::f1(float& x) {
>     x +=3D 2;
>     D d;
>     return d;
> }
>
> B& B::f2(float& x) {
>     x--;
>     return *this;
> }
>
> int main()
> {
>     float x(100.0f);
>     B b;
>     static_cast<D&>(b.f1(x)).f2(x);
>     return 0;
> }
>
>
> This often comes up when we have 2 families of hierarchy, but one family
> is descendent of the other. For example, assume we have a hierarchy of
> collection types.
> The parent class is Seq, with child classes Array, List. Then we want to
> have a parallel version of the whole family, then we make ParSeq a child
> class of Seq (with overriden methods), then ParArray, ParList child class=
es
> of ParSeq...
> It still feels awkward casting things all over again, including in CRTP.
>
> I think I saw CRTP once. Man...
>
> https://media0.giphy.com/media/11CXAq0P8h50GI/giphy.gif?cid=3D3640f6095c0=
1484b4e314375497147b0
>
>
>
> On Fri, Nov 30, 2018 at 2:25 PM Ville Voutilainen <
> ville.voutilainen@gmail.com> wrote:
>
>> On Fri, 30 Nov 2018 at 16:22, 'Thomas K=C3=B6ppe' via ISO C++ Standard -
>> Future Proposals <std-proposals@isocpp.org> wrote:
>> >
>> > On Friday, 30 November 2018 13:38:20 UTC, Vu Pham wrote:
>> >>
>> >>     float x(100.0f);
>> >>     B b;
>> >>     static_cast<B>(b.f1(x)).f2(x);   // this doesn't compile
>> >
>> >
>> > Shouldn't this say static_cast<B&>(b.f1(x)).f2(x))?
>>
>> Yes. That makes it compile. A downcast of references/pointers is a
>> hierarchy cast, but when its target is a new object, it's
>> no longer a hierarchy cast.
>>
>> --
>> You received this message because you are subscribed to the Google Group=
s
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n
>> email to std-proposals+unsubscribe@isocpp.org.
>> To post to this group, send email to std-proposals@isocpp.org.
>> To view this discussion on the web visit
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFk2RUaAnC=
Rn66P4mkZYaiN0AMWLX2V46KtWZQ0S3C2mJij_sQ%40mail.gmail.com
>> .
>>
>
>
> --
> PHAM Hoai Vu
> LinkedIn: linkedin.com/in/vuphoai
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFhKpXGTfjz=
9RA8t2en%2BEGTxP_WZjfG_tbYD5i3B%2BRQvobAB9Q%40mail.gmail.com
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFhKpXGTfj=
z9RA8t2en%2BEGTxP_WZjfG_tbYD5i3B%2BRQvobAB9Q%40mail.gmail.com?utm_medium=3D=
email&utm_source=3Dfooter>
> .
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/201811301545=
42.5181497.55947.67133%40gmail.com
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/20181130154=
542.5181497.55947.67133%40gmail.com?utm_medium=3Demail&utm_source=3Dfooter>
> .
>


--=20
PHAM Hoai Vu
LinkedIn: linkedin.com/in/vuphoai

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAFhKpXHBX2RYUsFUMBMUCRZKOgU31_KzxG30oq1OM-s%2BA=
EG2Kw%40mail.gmail.com.

--000000000000a9cca2057be46dbb
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">It is knowingly hard to do anything simple in C++. I guess=
 it will make everything easier if we just pretend all those lvalue referen=
ces to be pointers.<br></div><br><div class=3D"gmail_quote"><div dir=3D"ltr=
">On Fri, Nov 30, 2018 at 3:45 PM Tony V E &lt;<a href=3D"mailto:tvaneerd@g=
mail.com">tvaneerd@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"g=
mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l=
eft:1ex"><div lang=3D"en-US" style=3D"background-color:rgb(255,255,255);lin=
e-height:initial">                                                         =
                             <div style=3D"width:100%;font-size:initial;fon=
t-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,=
125);text-align:initial;background-color:rgb(255,255,255)">You are returnin=
g references to stack objects when you return C and D. That&#39;s undefined=
 behavior. The object is destroyed, then you return a reference to it.</div=
>                                                                          =
                                                           <div style=3D"wi=
dth:100%;font-size:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-ser=
if,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(=
255,255,255)"><br style=3D"display:initial"></div>                         =
                                                                           =
                                                                           =
                    <div style=3D"font-size:initial;font-family:Calibri,&#3=
9;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);text-align:init=
ial;background-color:rgb(255,255,255)">Sent=C2=A0from=C2=A0my=C2=A0BlackBer=
ry=C2=A0portable=C2=A0Babbage=C2=A0Device</div>                            =
                                                                           =
                                                                           =
<table width=3D"100%" style=3D"background-color:white;border-spacing:0px"> =
<tbody><tr><td colspan=3D"2" style=3D"font-size:initial;text-align:initial;=
background-color:rgb(255,255,255)">                           <div style=3D=
"border-style:solid none none;border-top-color:rgb(181,196,223);border-top-=
width:1pt;padding:3pt 0in 0in;font-family:Tahoma,&#39;BB Alpha Sans&#39;,&#=
39;Slate Pro&#39;;font-size:10pt">  <div><b>From: </b>Vu Pham</div><div><b>=
Sent: </b>Friday, November 30, 2018 9:50 AM</div><div><b>To: </b><a href=3D=
"mailto:std-proposals@isocpp.org" target=3D"_blank">std-proposals@isocpp.or=
g</a></div><div><b>Reply To: </b><a href=3D"mailto:std-proposals@isocpp.org=
" target=3D"_blank">std-proposals@isocpp.org</a></div><div><b>Subject: </b>=
Re: [std-proposals] Re: Return this or *this in overridden method in child =
class?</div></div></td></tr></tbody></table><div style=3D"border-style:soli=
d none none;border-top-color:rgb(186,188,209);border-top-width:1pt;font-siz=
e:initial;text-align:initial;background-color:rgb(255,255,255)"></div><br><=
div id=3D"m_-5320172694870957515_originalContent"><div dir=3D"ltr"><div dir=
=3D"ltr"><div dir=3D"ltr"><div>Yes, you&#39;re right, it should be B&amp;. =
The example was oversimplified, here is a better one:</div><div><span style=
=3D"font-family:monospace,monospace"><br></span></div><div><span style=3D"f=
ont-family:monospace,monospace">class A {<br>public:<br>=C2=A0=C2=A0=C2=A0 =
A&amp; f1(float&amp; x);<br>};<br><br>class C: public A { };<br><br>class B=
: public A {<br>public:<br>=C2=A0=C2=A0=C2=A0 A&amp; f1(float&amp; x);<br>=
=C2=A0=C2=A0=C2=A0 B&amp; f2(float&amp; x);<br>};<br><br>class D: public B =
{ };<br><br>A&amp; A::f1(float&amp; x) {<br>=C2=A0=C2=A0=C2=A0 x++;<br>=C2=
=A0=C2=A0=C2=A0 C c;<br>=C2=A0=C2=A0=C2=A0 return c;<br>}<br><br>A&amp; B::=
f1(float&amp; x) {<br>=C2=A0=C2=A0=C2=A0 x +=3D 2;<br>=C2=A0=C2=A0=C2=A0 D =
d;<br>=C2=A0=C2=A0=C2=A0 return d;<br>}<br><br>B&amp; B::f2(float&amp; x) {=
<br>=C2=A0=C2=A0=C2=A0 x--;<br>=C2=A0=C2=A0=C2=A0 return *this;<br>}<br>=C2=
=A0=C2=A0=C2=A0 <br>int main()<br>{<br>=C2=A0=C2=A0=C2=A0 float x(100.0f);<=
br>=C2=A0=C2=A0=C2=A0 B b;<br>=C2=A0=C2=A0=C2=A0 static_cast&lt;D&amp;&gt;(=
b.f1(x)).f2(x);<br>=C2=A0=C2=A0=C2=A0 return 0;<br>}</span></div><div><br><=
/div><div><br></div><div>This often comes up when we have 2 families of hie=
rarchy, but one family is descendent of the other. For example, assume we h=
ave a hierarchy of collection types.</div><div>The parent class is Seq, wit=
h child classes Array, List. Then we want to have a parallel version of the=
 whole family, then we make ParSeq a child class of Seq (with overriden met=
hods), then ParArray, ParList child classes of ParSeq...</div><div>It still=
 feels awkward casting things all over again, including in CRTP.<br></div><=
div><br></div><div>I think I saw CRTP once. Man...<br></div><div></div><div=
><a href=3D"https://media0.giphy.com/media/11CXAq0P8h50GI/giphy.gif?cid=3D3=
640f6095c01484b4e314375497147b0" target=3D"_blank">https://media0.giphy.com=
/media/11CXAq0P8h50GI/giphy.gif?cid=3D3640f6095c01484b4e314375497147b0</a><=
/div><div><br></div><div><br></div></div></div></div><br><div class=3D"gmai=
l_quote"><div dir=3D"ltr">On Fri, Nov 30, 2018 at 2:25 PM Ville Voutilainen=
 &lt;<a href=3D"mailto:ville.voutilainen@gmail.com" target=3D"_blank">ville=
..voutilainen@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_q=
uote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1e=
x">On Fri, 30 Nov 2018 at 16:22, &#39;Thomas K=C3=B6ppe&#39; via ISO C++ St=
andard -<br>
Future Proposals &lt;<a href=3D"mailto:std-proposals@isocpp.org" target=3D"=
_blank">std-proposals@isocpp.org</a>&gt; wrote:<br>
&gt;<br>
&gt; On Friday, 30 November 2018 13:38:20 UTC, Vu Pham wrote:<br>
&gt;&gt;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0float x(100.0f);<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0B b;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0static_cast&lt;B&gt;(b.f1(x)).f2(x);=C2=A0 =C2=
=A0// this doesn&#39;t compile<br>
&gt;<br>
&gt;<br>
&gt; Shouldn&#39;t this say static_cast&lt;B&amp;&gt;(b.f1(x)).f2(x))?<br>
<br>
Yes. That makes it compile. A downcast of references/pointers is a<br>
hierarchy cast, but when its target is a new object, it&#39;s<br>
no longer a hierarchy cast.<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%2Bunsubscribe@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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAFk2RUaAnCRn66P4mkZYaiN0AMWLX2V46KtW=
ZQ0S3C2mJij_sQ%40mail.gmail.com" rel=3D"noreferrer" target=3D"_blank">https=
://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFk2RUaAnCRn66P4mk=
ZYaiN0AMWLX2V46KtWZQ0S3C2mJij_sQ%40mail.gmail.com</a>.<br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"m=
_-5320172694870957515gmail_signature" data-smartmail=3D"gmail_signature"><d=
iv dir=3D"ltr"><div><div dir=3D"ltr"><div>PHAM Hoai Vu</div><div>LinkedIn:=
=C2=A0<a href=3D"http://linkedin.com/in/vuphoai" target=3D"_blank">linkedin=
..com/in/vuphoai</a></div></div></div></div></div>

<p></p>

-- <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" 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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAFhKpXGTfjz9RA8t2en%2BEGTxP_WZjfG_tb=
YD5i3B%2BRQvobAB9Q%40mail.gmail.com?utm_medium=3Demail&amp;utm_source=3Dfoo=
ter" target=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-p=
roposals/CAFhKpXGTfjz9RA8t2en%2BEGTxP_WZjfG_tbYD5i3B%2BRQvobAB9Q%40mail.gma=
il.com</a>.<br>
<br></div></div>

<p></p>

-- <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" 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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/20181130154542.5181497.55947.67133%40=
gmail.com?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/20181130154542.51=
81497.55947.67133%40gmail.com</a>.<br>
</blockquote></div><br clear=3D"all"><br>-- <br><div dir=3D"ltr" class=3D"g=
mail_signature" data-smartmail=3D"gmail_signature"><div dir=3D"ltr"><div><d=
iv dir=3D"ltr"><div>PHAM Hoai Vu</div><div>LinkedIn:=C2=A0<a href=3D"http:/=
/linkedin.com/in/vuphoai" target=3D"_blank">linkedin.com/in/vuphoai</a></di=
v></div></div></div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAFhKpXHBX2RYUsFUMBMUCRZKOgU31_KzxG30=
oq1OM-s%2BAEG2Kw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFhKpXHBX2RYUs=
FUMBMUCRZKOgU31_KzxG30oq1OM-s%2BAEG2Kw%40mail.gmail.com</a>.<br />

--000000000000a9cca2057be46dbb--

.