Topic: Is it necessary to add a stronger
Author: "zhouhongyu1104@gmail.com" <zhouhongyu1104@gmail.com>
Date: Sun, 12 Aug 2018 03:03:20 +0800
Raw View
This is a multi-part message in MIME format.
------=_001_NextPart373518241567_=----
Content-Type: text/plain; charset="UTF-8"
So this is just static virtual inheritance in all but name.
It depends on what you need it for. If you just want to declare an
interface that a class has to abide by, use templates and the CRTP. That
way a class X wont compile if it inherits from parent<X> and doesnt
implement the static methods of X that the parent uses. If you want to
avoid the parent class you can SFINAE your way out of this - passing the
class name as a template parameter to any method that needs it, instead of
as an argument.
I don't know if concepts cover static methods, but they'd make that whole
process a lot simpler.
If you have a specific reason to cast to a generic parent type (e.g.
storing a bunch of different child classes in a container, via pointers to
the parent class type), the template approach won't help. I guess a
"pseudostatic" keyword for this purpose - i.e. a method with the rules of
static, that can be accessed as static, but can also be accessed via *this*
- would change that, but that's expensive and I honestly haven't seen any
legitimate (i.e. beyond toy examples) need for that functionality in modern
C++.
On Fri, 10 Aug 2018, 20:18 zhouhongyu1104@gmail.com, <
zhouhongyu1104@gmail.com> wrote:
> yes :)
>
> ------------------------------
> zhouhongyu1104@gmail.com
>
>
> *From:* Nicol Bolas <jmckesson@gmail.com>
> *Date:* 2018-08-11 03:17
> *To:* ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
> *CC:* zhouhongyu1104 <zhouhongyu1104@gmail.com>
> *Subject:* Re: Is it necessary to add a stronger keyword than `const`?
> On Friday, August 10, 2018 at 2:19:49 PM UTC-4, zhouhon...@gmail.com
> wrote:
>
>> Thank you for your reply. Someone mentioned virtual static, this is
>> exactly what I want to express. I want to use inheritable static methods in
>> polymorphism.
>>
>
> What would that mean? How would it be any different from a `virtual`,
> non-static method? Do you just want to prevent yourself from accessing
> members through `this`?
>
> --
> 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/201808110318476054020%40gmail.com
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/201808110318476054020%40gmail.com?utm_medium=email&utm_source=footer>
> .
>
--
You received this message because you are subscribed to a topic in the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this topic, visit https://groups.google.com/a/isocpp.org/d/topic/std-proposals/WRTJNTzPef0/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAC%2B0CCN5jgE%2BOxoGcWmXqYO7G2Kke5Hro%3DZy%2BWZUNAe1B4NLmw%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/isocpp.org/d/msgid/std-proposals/201808120303180660901%40gmail.com.
------=_001_NextPart373518241567_=----
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<html><head></head><body><div class=3D"">thank you very much~<br><br>and I =
think the template approach could help<br><br>class Base {<br> p=
ublic:<br> virtual void vfunc() { std::cout << "Base::vf=
unc" << std::endl; }<br>};<br>template <class impl=3D""> class BaseCR=
TP : public Base {<br> public:<br> virtual void vfunc() =
{ Impl::vfunc(); }<br>};<br>class Derived_1 : public BaseCRTP<derived_1> {<=
br> public:<br> static void vfunc() { std::cout <<=
"Derived_1 static vfunc" << std::endl; }<br>};<br>class Derived_2 : =
public BaseCRTP<derived_2> {<br> public:<br> static void=
vfunc() { std::cout << "Derived_2 static vfunc" << std::endl; =
}<br>};<br>int main() {<br> deque<base *=3D""> childs;<br>&nbs=
p; childs.emplace_back(new Derived_1());<br> childs.emp=
lace_back(new Derived_2());<br> for (auto c : childs)<br> =
; c->vfunc();<br> return 0;<br>}<br></=
derived_2></derived_1></class></div><div> </div><hr style=3D"WIDTH: 21=
0px; HEIGHT: 1px" color=3D"#b5c4df" size=3D"1" align=3D"left"><div><span><d=
iv style=3D"MARGIN: 10px; FONT-FAMILY: verdana; FONT-SIZE: 10pt"><div>zhouh=
ongyu1104@gmail.com</div></div></span></div><blockquote style=3D"margin-Top=
: 0px; margin-Bottom: 0px; margin-Left: 0.5em"><div> </div><div style=
=3D"border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm"><=
div style=3D"PADDING-RIGHT: 8px; PADDING-LEFT: 8px; FONT-SIZE: 12px;FONT-FA=
MILY:tahoma;COLOR:#000000; BACKGROUND: #efefef; PADDING-BOTTOM: 8px; PADDIN=
G-TOP: 8px"><div><b>From:</b> <a href=3D"mailto:jake.arkinstall@gmail.=
com">Jake Arkinstall</a></div><div><b>Date:</b> 2018-08-11 19:00<=
/div><div><b>To:</b> <a href=3D"mailto:std-proposals@isocpp.org">std-p=
roposals</a></div><div><b>Subject:</b> Re: [std-proposals] Re: Re: Is =
it necessary to add a stronger keyword than `const`?</div></div></div><div>=
<div class=3D""><style>div.FoxDIV_20180812021536154 { font-size: 10.5pt }
</style><div style=3D"height:initial" class=3D"FoxDIV_20180812021536154"><d=
iv dir=3D"auto"><div dir=3D"auto">So this is just static virtual inheritanc=
e in all but name.</div><div dir=3D"auto"><br></div><div dir=3D"auto">It de=
pends on what you need it for. If you just want to declare an interface tha=
t a class has to abide by, use templates and the CRTP. That way a class X w=
ont compile if it inherits from parent<X> and doesnt implement the st=
atic methods of X that the parent uses. If you want to avoid the pare=
nt class you can SFINAE your way out of this - passing the class name as a =
template parameter to any method that needs it, instead of as an argument.<=
/div><div dir=3D"auto"><span style=3D"font-family:sans-serif"><br></span></=
div><div dir=3D"auto">I<span style=3D"font-family:sans-serif"> don't know i=
f concepts cover static methods, but they'd make that whole process a lot s=
impler.</span></div><div dir=3D"auto"><div dir=3D"auto" style=3D"font-famil=
y:sans-serif"><br></div><div dir=3D"auto" style=3D"font-family:sans-serif">=
If you have a specific reason to cast to a generic parent type (e.g. storin=
g a bunch of different child classes in a container, via pointers to the pa=
rent class type), the template approach won't help. I guess a "pseudostatic=
" keyword for this purpose - i.e. a method with the rules of static, that c=
an be accessed as static, but can also be accessed via <i>this</i> - would =
change that, but that's expensive and I honestly haven't seen any legitimat=
e (i.e. beyond toy examples) need for that functionality in modern C++.</di=
v></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Fri, 10 Au=
g 2018, 20:18 <a href=3D"mailto:zhouhongyu1104@gmail.com">zhouhongyu1104@gm=
ail.com</a>, <<a href=3D"mailto:zhouhongyu1104@gmail.com">zhouhongyu1104=
@gmail.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><di=
v>yes :)</div><div> </div><hr style=3D"WIDTH:210px;HEIGHT:1px" color=
=3D"#b5c4df" size=3D"1" align=3D"left"><div><span><div style=3D"MARGIN:10px=
;FONT-FAMILY:verdana;FONT-SIZE:10pt"><div><a href=3D"mailto:zhouhongyu1104@=
gmail.com" target=3D"_blank" rel=3D"noreferrer">zhouhongyu1104@gmail.com</a=
></div></div></span></div><blockquote style=3D"margin-Top:0px;margin-Bottom=
:0px;margin-Left:0.5em"><div> </div><div style=3D"border:none;border-t=
op:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm"><div style=3D"PADDING-RIG=
HT:8px;PADDING-LEFT:8px;FONT-SIZE:12px;FONT-FAMILY:tahoma;COLOR:#000000;BAC=
KGROUND:#efefef;PADDING-BOTTOM:8px;PADDING-TOP:8px"><div><b>From:</b> =
<a href=3D"mailto:jmckesson@gmail.com" target=3D"_blank" rel=3D"noreferrer"=
>Nicol Bolas</a></div><div><b>Date:</b> 2018-08-11 03:17</div><di=
v><b>To:</b> <a href=3D"mailto:std-proposals@isocpp.org" target=3D"_bl=
ank" rel=3D"noreferrer">ISO C++ Standard - Future Proposals</a></div><div><=
b>CC:</b> <a href=3D"mailto:zhouhongyu1104@gmail.com" target=3D"_blank=
" rel=3D"noreferrer">zhouhongyu1104</a></div><div><b>Subject:</b> Re: =
Is it necessary to add a stronger keyword than `const`?</div></div></div><d=
iv><div><div style=3D"height:initial" class=3D"m_-3458072061566013981FoxDIV=
_20180811031721938"><div dir=3D"ltr">On Friday, August 10, 2018 at 2:19:49 =
PM UTC-4, <a href=3D"mailto:zhouhon...@gmail.com" target=3D"_blank" rel=3D"=
noreferrer">zhouhon...@gmail.com</a> wrote:
<div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;=
border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Thank you for=
your reply. Someone mentioned virtual static, this is exactly what I want =
to express. I want to use inheritable static methods in polymorphism.<br></=
div></blockquote></div>
<div><br></div><div>What would that mean? How would it be any different fro=
m a `virtual`, non-static method? Do you just want to prevent yourself from=
accessing members through `this`?<br></div></div></div></div></div></block=
quote></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" 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/201808110318476054020%40gmail.com?utm=
_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" rel=3D"noreferre=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/20180811031=
8476054020%40gmail.com</a>.<br>
</blockquote></div>
<p></p>
-- <br>
You received this message because you are subscribed to a topic in the Goog=
le Groups "ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this topic, visit <a href=3D"https://groups.google.com/=
a/isocpp.org/d/topic/std-proposals/WRTJNTzPef0/unsubscribe">https://groups.=
google.com/a/isocpp.org/d/topic/std-proposals/WRTJNTzPef0/unsubscribe</a>.<=
br>
To unsubscribe from this group and all its topics, send an email to <a href=
=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposals+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/CAC%2B0CCN5jgE%2BOxoGcWmXqYO7G2Kke5Hr=
o%3DZy%2BWZUNAe1B4NLmw%40mail.gmail.com?utm_medium=3Demail&utm_source=
=3Dfooter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC=
%2B0CCN5jgE%2BOxoGcWmXqYO7G2Kke5Hro%3DZy%2BWZUNAe1B4NLmw%40mail.gmail.com</=
a>.<br>
</div></div></div></blockquote></body></html>
<p></p>
-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/201808120303180660901%40gmail.com?utm=
_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/a/isocpp.org=
/d/msgid/std-proposals/201808120303180660901%40gmail.com</a>.<br />
------=_001_NextPart373518241567_=------
.