Topic: Non-virtual methods without body ( "=0" )


Author: NeoCode <neoprogramming@gmail.com>
Date: Thu, 24 Mar 2016 06:41:42 -0700 (PDT)
Raw View
------=_Part_721_7024112.1458826902810
Content-Type: multipart/alternative;
 boundary="----=_Part_722_741189912.1458826902811"

------=_Part_722_741189912.1458826902811
Content-Type: text/plain; charset=UTF-8

Sometimes (especially for templates) I need to require the the availability
of methods in a derived class. This can be done with pure virtual
functions, but virtual inheritance is not always necessary.
This is a simple, cheap and obvious way to require the availability of
methods in a derived class. Also it will be useful in the implementation of
concepts for the future.
{
   void foo() = 0;
};

struct Derived1 : Base
{
   void foo() { /* do something */ }
};

struct Derived2 : Base
{
  // without 'foo'
};

Derived1 d1; // ok
Derived2 d2; // compile error


template<typename T> // we can specify a requirement "deriving from Base"
using concept syntax...
void bar()
{
  T *pt = new T;
  pt->foo();
}

bar<Derived1>(); // ok
bar<Derived2>(); // compile error


--
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/d835ac71-9d4a-47f3-bf64-5acfc84c5876%40isocpp.org.

------=_Part_722_741189912.1458826902811
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Sometimes (especially for templates) I need to require the=
 the availability of methods in a derived class.=C2=A0This can be done with=
 pure virtual functions, but virtual inheritance is not always necessary.<d=
iv>This is a simple, cheap and obvious way to require the availability of m=
ethods in a derived class. Also it will be useful in the implementation of =
concepts for the future.</div><div><div class=3D"prettyprint" style=3D"bord=
er: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-color: =
rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettypri=
nt"><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> foo</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><f=
ont color=3D"#000088"><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span></font><span style=3D"color: #606;" class=3D"styled-by-prettify">D=
erived1</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Base</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br></span><font color=3D"#000088"><span style=3D=
"color: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> foo</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">=
/* do something */</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}=
</span></font><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">Derived2</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Base</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 </span><span style=3D"color: #800;" class=3D"styled-by-prettify">// =
without &#39;foo&#39;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
><br></span><span style=3D"color: #606;" class=3D"styled-by-prettify">Deriv=
ed1</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> d1</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #800;" class=3D"styled-by-prettify">// ok</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #606=
;" class=3D"styled-by-prettify">Derived2</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> d2</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pret=
tify">// compile error</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br><br><br></span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">template</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #800;" class=3D"styled-by-prettify">// we can specify a=
 requirement &quot;deriving from Base&quot;</span><span style=3D"color: #80=
0;" class=3D"styled-by-prettify"> using concept syntax...</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> bar</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 T </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
pt </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">new</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br>=C2=A0 pt</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">-&gt;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">foo</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br><br>bar</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&lt;</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Derive=
d1</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;();<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #800;" class=3D"styled-by-prettify">// ok</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>bar</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">Derived2</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&gt;();</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" cl=
ass=3D"styled-by-prettify">// compile error</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span></div></code></div><br><br></di=
v></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/d835ac71-9d4a-47f3-bf64-5acfc84c5876%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d835ac71-9d4a-47f3-bf64-5acfc84c5876=
%40isocpp.org</a>.<br />

------=_Part_722_741189912.1458826902811--
------=_Part_721_7024112.1458826902810--

.


Author: NeoCode <neoprogramming@gmail.com>
Date: Thu, 24 Mar 2016 06:44:04 -0700 (PDT)
Raw View
------=_Part_118_119207583.1458827044332
Content-Type: multipart/alternative;
 boundary="----=_Part_119_593965234.1458827044332"

------=_Part_119_593965234.1458827044332
Content-Type: text/plain; charset=UTF-8

Sometimes (especially for templates) I need to require the the availability
of methods in a derived class. This can be done with pure virtual
functions, but virtual inheritance is not always necessary.
This is a simple, cheap and obvious way to require the availability of
methods in a derived class. Also it will be useful in the implementation of
concepts for the future.

struct Base
{
   void foo() = 0;  // non-virtual member function without body
};

struct Derived1 : Base
{
   void foo() { /* do something */ }
};

struct Derived2 : Base
{
  // without 'foo'
};

Base b;      // compile error
Derived1 d1; // ok
Derived2 d2; // compile error


template<typename T> // we can specify a requirement "deriving from Base"
using concept syntax...
void bar()
{
  T *pt = new T;
  pt->foo();
}

bar<Derived1>(); // ok
bar<Derived2>(); // compile error


--
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/589ee193-534e-414a-90b8-3d55b2a95fc8%40isocpp.org.

------=_Part_119_593965234.1458827044332
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Sometimes (especially for templates) I need to requir=
e the the availability of methods in a derived class. This can be done with=
 pure virtual functions, but virtual inheritance is not always necessary.</=
div><div>This is a simple, cheap and obvious way to require the availabilit=
y of methods in a derived class. Also it will be useful in the implementati=
on of concepts for the future.</div><div><br></div><div><div class=3D"prett=
yprint" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-wor=
d; background-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div =
class=3D"subprettyprint"><font color=3D"#660066"><div class=3D"subprettypri=
nt">struct Base</div><div class=3D"subprettyprint">{</div><div class=3D"sub=
prettyprint">=C2=A0 =C2=A0void foo() =3D 0; =C2=A0// non-virtual member fun=
ction without body=C2=A0</div><div class=3D"subprettyprint">};</div><div cl=
ass=3D"subprettyprint"><br></div><div class=3D"subprettyprint">struct Deriv=
ed1 : Base</div><div class=3D"subprettyprint">{</div><div class=3D"subprett=
yprint">=C2=A0 =C2=A0void foo() { /* do something */ }</div><div class=3D"s=
ubprettyprint">};</div><div class=3D"subprettyprint"><br></div><div class=
=3D"subprettyprint">struct Derived2 : Base</div><div class=3D"subprettyprin=
t">{</div><div class=3D"subprettyprint">=C2=A0 // without &#39;foo&#39;</di=
v><div class=3D"subprettyprint">};</div><div class=3D"subprettyprint"><br>B=
ase b; =C2=A0 =C2=A0 =C2=A0// compile error</div><div class=3D"subprettypri=
nt">Derived1 d1; // ok</div><div class=3D"subprettyprint">Derived2 d2; // c=
ompile error</div><div class=3D"subprettyprint"><br></div><div class=3D"sub=
prettyprint"><br></div><div class=3D"subprettyprint">template&lt;typename T=
&gt; // we can specify a requirement &quot;deriving from Base&quot; using c=
oncept syntax...</div><div class=3D"subprettyprint">void bar()</div><div cl=
ass=3D"subprettyprint">{</div><div class=3D"subprettyprint">=C2=A0 T *pt =
=3D new T;</div><div class=3D"subprettyprint">=C2=A0 pt-&gt;foo();</div><di=
v class=3D"subprettyprint">}</div><div class=3D"subprettyprint"><br></div><=
div class=3D"subprettyprint">bar&lt;Derived1&gt;(); // ok</div><div class=
=3D"subprettyprint">bar&lt;Derived2&gt;(); // compile error</div></font></d=
iv></code></div><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">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/589ee193-534e-414a-90b8-3d55b2a95fc8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/589ee193-534e-414a-90b8-3d55b2a95fc8=
%40isocpp.org</a>.<br />

------=_Part_119_593965234.1458827044332--
------=_Part_118_119207583.1458827044332--

.


Author: "dgutson ." <danielgutson@gmail.com>
Date: Thu, 24 Mar 2016 10:51:31 -0300
Raw View
--001a1140a56277beb2052ecbbe68
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

El 24/3/2016 10:44, "NeoCode" <neoprogramming@gmail.com> escribi=C3=B3:
>
> Sometimes (especially for templates) I need to require the the
availability of methods in a derived class. This can be done with pure
virtual functions, but virtual inheritance is not always necessary.
> This is a simple, cheap and obvious way to require the availability of
methods in a derived class. Also it will be useful in the implementation of
concepts for the future.
>
> struct Base
> {
>    void foo() =3D 0;  // non-virtual member function without body
> };
>
> struct Derived1 : Base
> {
>    void foo() { /* do something */ }
> };
>
> struct Derived2 : Base
> {
>   // without 'foo'
> };
>
> Base b;      // compile error
> Derived1 d1; // ok
> Derived2 d2; // compile error

Not only you get a compiler error in the last line without such feature,
but you can also do this with a  static_assert and SFINAE (google for
SFINAE test if a method exists or alike and you'll get plenty of resources)=
..

>
>
> template<typename T> // we can specify a requirement "deriving from Base"
using concept syntax...
> void bar()
> {
>   T *pt =3D new T;
>   pt->foo();
> }
>
> bar<Derived1>(); // ok
> bar<Derived2>(); // compile error
>
>
> --
> 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/589ee193-534e-=
414a-90b8-3d55b2a95fc8%40isocpp.org
..

--=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/CAFdMc-1hCK94oddLzwVV8FE0NZO-0SXLiLQEUT1%3D3Bqoh=
fLq1w%40mail.gmail.com.

--001a1140a56277beb2052ecbbe68
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<p dir=3D"ltr"><br>
El 24/3/2016 10:44, &quot;NeoCode&quot; &lt;<a href=3D"mailto:neoprogrammin=
g@gmail.com">neoprogramming@gmail.com</a>&gt; escribi=C3=B3:<br>
&gt;<br>
&gt; Sometimes (especially for templates) I need to require the the availab=
ility of methods in a derived class. This can be done with pure virtual fun=
ctions, but virtual inheritance is not always necessary.<br>
&gt; This is a simple, cheap and obvious way to require the availability of=
 methods in a derived class. Also it will be useful in the implementation o=
f concepts for the future.<br>
&gt;<br>
&gt; struct Base<br>
&gt; {<br>
&gt; =C2=A0 =C2=A0void foo() =3D 0; =C2=A0// non-virtual member function wi=
thout body=C2=A0<br>
&gt; };<br>
&gt;<br>
&gt; struct Derived1 : Base<br>
&gt; {<br>
&gt; =C2=A0 =C2=A0void foo() { /* do something */ }<br>
&gt; };<br>
&gt;<br>
&gt; struct Derived2 : Base<br>
&gt; {<br>
&gt; =C2=A0 // without &#39;foo&#39;<br>
&gt; };<br>
&gt;<br>
&gt; Base b; =C2=A0 =C2=A0 =C2=A0// compile error<br>
&gt; Derived1 d1; // ok<br>
&gt; Derived2 d2; // compile error</p>
<p dir=3D"ltr">Not only you get a compiler error in the last line without s=
uch feature, but you can also do this with a=C2=A0 static_assert and SFINAE=
 (google for SFINAE test if a method exists or alike and you&#39;ll get ple=
nty of resources).</p>
<p dir=3D"ltr">&gt;<br>
&gt;<br>
&gt; template&lt;typename T&gt; // we can specify a requirement &quot;deriv=
ing from Base&quot; using concept syntax...<br>
&gt; void bar()<br>
&gt; {<br>
&gt; =C2=A0 T *pt =3D new T;<br>
&gt; =C2=A0 pt-&gt;foo();<br>
&gt; }<br>
&gt;<br>
&gt; bar&lt;Derived1&gt;(); // ok<br>
&gt; bar&lt;Derived2&gt;(); // compile error<br>
&gt;<br>
&gt;<br>
&gt; -- <br>
&gt; You received this message because you are subscribed to the Google Gro=
ups &quot;ISO C++ Standard - Future Proposals&quot; group.<br>
&gt; To unsubscribe from this group and stop receiving emails from it, send=
 an email to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-=
proposals+unsubscribe@isocpp.org</a>.<br>
&gt; To post to this group, send email to <a href=3D"mailto:std-proposals@i=
socpp.org">std-proposals@isocpp.org</a>.<br>
&gt; To view this discussion on the web visit <a href=3D"https://groups.goo=
gle.com/a/isocpp.org/d/msgid/std-proposals/589ee193-534e-414a-90b8-3d55b2a9=
5fc8%40isocpp.org">https://groups.google.com/a/isocpp.org/d/msgid/std-propo=
sals/589ee193-534e-414a-90b8-3d55b2a95fc8%40isocpp.org</a>.<br>
</p>

<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/CAFdMc-1hCK94oddLzwVV8FE0NZO-0SXLiLQE=
UT1%3D3BqohfLq1w%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFdMc-1hCK94od=
dLzwVV8FE0NZO-0SXLiLQEUT1%3D3BqohfLq1w%40mail.gmail.com</a>.<br />

--001a1140a56277beb2052ecbbe68--

.


Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Thu, 24 Mar 2016 16:32:54 -0700 (PDT)
Raw View
------=_Part_10_307413644.1458862375052
Content-Type: multipart/alternative;
 boundary="----=_Part_11_333032833.1458862375053"

------=_Part_11_333032833.1458862375053
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Thursday, March 24, 2016 at 6:44:04 AM UTC-7, NeoCode wrote:
>
> Sometimes (especially for templates) I need to require the the=20
> availability of methods in a derived class. This can be done with pure=20
> virtual functions, but virtual inheritance is not always necessary.
>

Generally, if you're using templates, you're not using classical=20
polymorphism ("base class", "derived class") at all. That is, if your=20
template looks like

template<class T>
void call_foo(const T& t)
{
    t.foo();
}

then you won't have any entity in your program equivalent to "class Base";=
=20
instead, what you'll have is

struct Derived1 {
    void foo() const;
}

struct Derived2 {
    double foo(int arg=3D42);
};

etc. Notice the lack of classical inheritance, and the lack of a common=20
function signature between Derived1::foo() and Derived2::foo() =E2=80=94 ye=
t both=20
call_foo<Derived1> and call_foo<Derived2> are well-formed by design.


=20

> This is a simple, cheap and obvious way to require the availability of=20
> methods in a derived class. Also it will be useful in the implementation =
of=20
> concepts for the future.
>

I don't think that's true.
However, if you do pursue this idea further, you should definitely consider=
=20
how this feature would interact with the override contextual keyword. On=20
the one hand I'd definitely want to specify override if I'm trying to make=
=20
my derived class's foo method "override" the base class's method; but on=20
the other hand, I believe a lot of C++11 programmers use override as a=20
syntactic marker meaning "this member function is virtual", and might=20
object to your new use of override on non-virtual functions.

(Those two requirements might sound contradictory. The way the=20
contradiction is resolved today is that I *don't* try to make a derived=20
class that "overrides" a non-virtual method, because that's a terrible=20
idea.)


template<typename T> // we can specify a requirement "deriving from Base"=
=20
> using concept syntax...
>

The requirement you should specify here is not "deriving from Base", but=20
rather "implementing method foo()".

HTH,
=E2=80=93Arthur

--=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/cfbf6ee2-b874-495e-99ab-136b42c2828a%40isocpp.or=
g.

------=_Part_11_333032833.1458862375053
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Thursday, March 24, 2016 at 6:44:04 AM UTC-7, NeoCode w=
rote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8e=
x;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div>Som=
etimes (especially for templates) I need to require the the availability of=
 methods in a derived class. This can be done with pure virtual functions, =
but virtual inheritance is not always necessary.</div></div></blockquote><d=
iv><br></div><div>Generally, if you&#39;re using templates, you&#39;re not =
using classical polymorphism (&quot;base class&quot;, &quot;derived class&q=
uot;) at all. That is, if your template looks like</div><div><br></div><div=
 class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); borde=
r: 1px solid rgb(187, 187, 187); word-wrap: break-word;"><code class=3D"pre=
ttyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">template</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> call_foo</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> t</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br>=C2=A0 =C2=A0 t</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">foo</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">}</span></div></co=
de></div><div><br></div><div>then you won&#39;t have any entity in your pro=
gram equivalent to &quot;class Base&quot;; instead, what you&#39;ll have is=
</div><div><br></div><div class=3D"prettyprint" style=3D"background-color: =
rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-=
word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
606;" class=3D"styled-by-prettify">Derived1</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> foo</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">const=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" cla=
ss=3D"styled-by-prettify">Derived2</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">double</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> foo</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> arg</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span st=
yle=3D"color: #066;" class=3D"styled-by-prettify">42</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">};</span></div></code></div><div><br></div><div=
>etc. Notice the lack of classical inheritance, and the lack of a common fu=
nction signature between Derived1::foo() and Derived2::foo() =E2=80=94 yet =
both <font face=3D"courier new, monospace">call_foo&lt;Derived1&gt;</font> =
and <font face=3D"courier new, monospace">call_foo&lt;Derived2&gt;</font> a=
re well-formed by design.</div><div><br></div><div><br></div><div>=C2=A0<br=
></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"><div>T=
his is a simple, cheap and obvious way to require the availability of metho=
ds in a derived class. Also it will be useful in the implementation of conc=
epts for the future.</div></div></blockquote><div><br></div><div>I don&#39;=
t think that&#39;s true.</div><div>However, if you do pursue this idea furt=
her, you should definitely consider how this feature would interact with th=
e <font face=3D"courier new, monospace">override</font> contextual keyword.=
 On the one hand I&#39;d definitely want to specify override if I&#39;m try=
ing to make my derived class&#39;s <font face=3D"courier new, monospace">fo=
o</font> method &quot;override&quot; the base class&#39;s method; but on th=
e other hand, I believe a lot of C++11 programmers use <font face=3D"courie=
r new, monospace">override</font> as a syntactic marker meaning &quot;this =
member function is virtual&quot;, and might object to your new use of <font=
 face=3D"courier new, monospace">override</font> on non-virtual functions.<=
/div><div><br></div><div>(Those two requirements might sound contradictory.=
 The way the contradiction is resolved today is that I <i>don&#39;t</i> try=
 to make a derived class that &quot;overrides&quot; a non-virtual method, b=
ecause that&#39;s a terrible idea.)</div><div><br></div><div><br></div><blo=
ckquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-=
left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div style=
=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-color=
:rgb(250,250,250)"><code><div><font color=3D"#660066"><div>template&lt;type=
name T&gt; // we can specify a requirement &quot;deriving from Base&quot; u=
sing concept syntax...</div></font></div></code></div></div></div></blockqu=
ote><div><br></div><div>The requirement you should specify here is not &quo=
t;deriving from Base&quot;, but rather &quot;implementing method foo()&quot=
;.</div><div><br></div><div>HTH,</div><div>=E2=80=93Arthur</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/cfbf6ee2-b874-495e-99ab-136b42c2828a%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/cfbf6ee2-b874-495e-99ab-136b42c2828a=
%40isocpp.org</a>.<br />

------=_Part_11_333032833.1458862375053--
------=_Part_10_307413644.1458862375052--

.