Topic: Go-like embedding


Author: NeoCode <neoprogramming@gmail.com>
Date: Wed, 2 Mar 2016 05:27:30 -0800 (PST)
Raw View
------=_Part_449_579399996.1456925250415
Content-Type: multipart/alternative;
 boundary="----=_Part_450_1470392765.1456925250415"

------=_Part_450_1470392765.1456925250415
Content-Type: text/plain; charset=UTF-8

In Go programming language, there is a feature named "emedding", which is
used instead of classic c++-like inheritance.
For example:

type SmallBox struct {
        a, b, c int
}
type BigBox struct {
        Timestamp time.Time
        SmallBox  // <<< embedding
        Name []string
}

This is very simple and low-level extension of the concept of
inheritance; the programmer explicitly specifies the location of the base
object in the successor. It is strange that this simple and obvious
opportunity not appeared in the C language.

I propose enhanced (compared with Go) feature of such embedding. We can use
the existing "inline" keyword (or some other keyword, eg. "embed") to
indicate the embedded fields.

struct SmallBox {
  int a, b, c;
};

struct BigBox {
 time_t Timestamp;
 inline SmallBox inlinedBox;
 std::string Name;
};

As a result, we can access to the fields of SmallBox both directly and
through an intermediate name "inlinedBox":

BigBox box;
box.a = 10; //directly, like inheritance
box.inlinedBox.b = 10; // using an intermediate name, like aggregation


--
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/e85c46fd-5e5c-4e43-86ae-978da17cda0c%40isocpp.org.

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

<div dir=3D"ltr">In Go programming language,=C2=A0there is a feature named =
&quot;emedding&quot;,=C2=A0which is used instead of classic c++-like inheri=
tance.<br>For example:<div><br><div><div class=3D"prettyprint" style=3D"bor=
der: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-color:=
 rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettypr=
int"><span class=3D"hljs-keyword" style=3D"font-size: 12px; vertical-align:=
 baseline; outline: 0px; color: rgb(51, 51, 51); font-weight: 700; font-fam=
ily: Menlo, Monaco, &#39;Courier New&#39;, monospace; line-height: 22.39999=
96185303px; white-space: pre-wrap;"><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">type</span></span><span style=3D"color: rgb(51, 51, 51);=
 font-family: Menlo, Monaco, &#39;Courier New&#39;, monospace; font-size: 1=
2px; line-height: 22.3999996185303px; white-space: pre-wrap; background-col=
or: rgb(248, 248, 248);"><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">S=
mallBox</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span></span><span class=3D"hljs-keyword" style=3D"font-size: 12px; vertical=
-align: baseline; outline: 0px; color: rgb(51, 51, 51); font-weight: 700; f=
ont-family: Menlo, Monaco, &#39;Courier New&#39;, monospace; line-height: 2=
2.3999996185303px; white-space: pre-wrap;"><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">struct</span></span><span style=3D"color: rgb(51,=
 51, 51); font-family: Menlo, Monaco, &#39;Courier New&#39;, monospace; fon=
t-size: 12px; line-height: 22.3999996185303px; white-space: pre-wrap; backg=
round-color: rgb(248, 248, 248);"><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span></span><span style=3D"font-family: Menlo, Monaco, &#39;Courier Ne=
w&#39;, monospace; font-size: 12px; line-height: 22.3999996185303px; white-=
space: pre-wrap; background-color: rgb(248, 248, 248);"><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 =C2=A0 =C2=A0 a</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> b</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> c </span></span><span class=3D"hljs-keywor=
d" style=3D"font-size: 12px; vertical-align: baseline; outline: 0px; color:=
 rgb(51, 51, 51); font-weight: 700; font-family: Menlo, Monaco, &#39;Courie=
r New&#39;, monospace; line-height: 22.3999996185303px; white-space: pre-wr=
ap;"><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span></=
span><span style=3D"color: rgb(51, 51, 51); font-family: Menlo, Monaco, &#3=
9;Courier New&#39;, monospace; font-size: 12px; line-height: 22.39999961853=
03px; white-space: pre-wrap; background-color: rgb(248, 248, 248);"><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span></span><span =
style=3D"color: rgb(51, 51, 51); font-family: Menlo, Monaco, &#39;Courier N=
ew&#39;, monospace; font-size: 12px; line-height: 22.3999996185303px; white=
-space: pre-wrap; background-color: rgb(248, 248, 248);"><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br></span></span><span class=3D"hljs-keywor=
d" style=3D"font-size: 12px; vertical-align: baseline; outline: 0px; color:=
 rgb(51, 51, 51); font-weight: 700; font-family: Menlo, Monaco, &#39;Courie=
r New&#39;, monospace; line-height: 22.3999996185303px; white-space: pre-wr=
ap;"><span style=3D"color: #000;" class=3D"styled-by-prettify">type</span><=
/span><span style=3D"color: rgb(51, 51, 51); font-family: Menlo, Monaco, &#=
39;Courier New&#39;, monospace; font-size: 12px; line-height: 22.3999996185=
303px; white-space: pre-wrap; background-color: rgb(248, 248, 248);"><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">BigBox</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span></span><span class=3D"hljs-k=
eyword" style=3D"font-size: 12px; vertical-align: baseline; outline: 0px; c=
olor: rgb(51, 51, 51); font-weight: 700; font-family: Menlo, Monaco, &#39;C=
ourier New&#39;, monospace; line-height: 22.3999996185303px; white-space: p=
re-wrap;"><span style=3D"color: #008;" class=3D"styled-by-prettify">struct<=
/span></span><span style=3D"color: rgb(51, 51, 51); font-family: Menlo, Mon=
aco, &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 22.399=
9996185303px; white-space: pre-wrap; background-color: rgb(248, 248, 248);"=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </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>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </=
span></span><span style=3D"color: rgb(51, 51, 51); font-family: Menlo, Mona=
co, &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 22.3999=
996185303px; white-space: pre-wrap; background-color: rgb(248, 248, 248);">=
<span style=3D"color: #606;" class=3D"styled-by-prettify">Timestamp</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> time</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">Time</span></span><span style=3D=
"color: rgb(51, 51, 51); font-family: Menlo, Monaco, &#39;Courier New&#39;,=
 monospace; font-size: 12px; line-height: 22.3999996185303px; white-space: =
pre-wrap; background-color: rgb(248, 248, 248);"><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><spa=
n style=3D"color: #606;" class=3D"styled-by-prettify">SmallBox</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0</span><span sty=
le=3D"color: #800;" class=3D"styled-by-prettify">// &lt;&lt;&lt; embedding<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #606;" class=3D"styled-by=
-prettify">Name</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">[]</=
span></span><span class=3D"hljs-keyword" style=3D"font-size: 12px; vertical=
-align: baseline; outline: 0px; color: rgb(51, 51, 51); font-weight: 700; f=
ont-family: Menlo, Monaco, &#39;Courier New&#39;, monospace; line-height: 2=
2.3999996185303px; white-space: pre-wrap;"><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">string</span></span><span style=3D"color: rgb(51,=
 51, 51); font-family: Menlo, Monaco, &#39;Courier New&#39;, monospace; fon=
t-size: 12px; line-height: 22.3999996185303px; white-space: pre-wrap; backg=
round-color: rgb(248, 248, 248);"><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span></span><span style=3D"color: rgb(51, 51, 51); f=
ont-family: Menlo, Monaco, &#39;Courier New&#39;, monospace; font-size: 12p=
x; line-height: 22.3999996185303px; white-space: pre-wrap; background-color=
: rgb(248, 248, 248);"><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">}</span></span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span></div></code></div><br>This is very simple and low-level ext=
ension of the concept of inheritance;=C2=A0the programmer explicitly specif=
ies the location of the base object in the successor.=C2=A0It is strange th=
at this simple and obvious opportunity not appeared in the C language.</div=
></div><div><br></div><div>I propose enhanced (compared with Go) feature of=
 such embedding.=C2=A0We can use the existing &quot;inline&quot; keyword (o=
r some other keyword, eg. &quot;embed&quot;) to indicate the embedded field=
s.<br></div><div><br></div><div><div class=3D"prettyprint" style=3D"border:=
 1px solid rgb(187, 187, 187); word-wrap: break-word; background-color: rgb=
(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"=
><font color=3D"#660066"><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Small=
Box</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> a</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> b</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> c</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #606;" class=3D"styled-by-prettify">BigBox</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </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>=C2=A0time_t </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Timestamp</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</span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">inline</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettif=
y">SmallBox</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> inlinedBox</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">string</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #606;" class=3D"styled-by-prettify">Name</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><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span></font></div></code></div><br>As a result, =
we can access to the fields of=C2=A0SmallBox=C2=A0both directly and through=
 an intermediate name &quot;inlinedBox&quot;:<br></div><div><br></div><div>=
<div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); w=
ord-wrap: break-word; background-color: rgb(250, 250, 250);"><code class=3D=
"prettyprint"><div class=3D"subprettyprint"><font color=3D"#660066"><span s=
tyle=3D"color: #606;" class=3D"styled-by-prettify">BigBox</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> box</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>box</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">a </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">10</=
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: #800;" class=3D"styled-by-prettify">//directly, </span></font><f=
ont color=3D"#880000"><span style=3D"color: #800;" class=3D"styled-by-prett=
ify">like inheritance</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br>box</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">i=
nlinedBox</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">b </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #066;" class=3D"styled-by-prettify">10</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"style=
d-by-prettify">// </span></font><span style=3D"font-family: Arial, Helvetic=
a, sans-serif; background-color: rgb(255, 255, 255);"><span style=3D"color:=
 #800;" class=3D"styled-by-prettify">using </span><span style=3D"color: #80=
0;" class=3D"styled-by-prettify">an intermediate name, </span></span><span =
style=3D"color: rgb(136, 0, 0); font-family: Arial, Helvetica, sans-serif;"=
><span style=3D"color: #800;" class=3D"styled-by-prettify">like aggregation=
</span></span></div></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/e85c46fd-5e5c-4e43-86ae-978da17cda0c%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e85c46fd-5e5c-4e43-86ae-978da17cda0c=
%40isocpp.org</a>.<br />

------=_Part_450_1470392765.1456925250415--
------=_Part_449_579399996.1456925250415--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Wed, 2 Mar 2016 05:46:28 -0800 (PST)
Raw View
------=_Part_6304_1134666666.1456926388582
Content-Type: multipart/alternative;
 boundary="----=_Part_6305_1116270529.1456926388583"

------=_Part_6305_1116270529.1456926388583
Content-Type: text/plain; charset=UTF-8

On Wednesday, March 2, 2016 at 8:27:30 AM UTC-5, NeoCode wrote:
>
> In Go programming language, there is a feature named "emedding", which is
> used instead of classic c++-like inheritance.
> For example:
>
> type SmallBox struct {
>         a, b, c int
> }
> type BigBox struct {
>         Timestamp time.Time
>         SmallBox  // <<< embedding
>         Name []string
> }
>
> This is very simple and low-level extension of the concept of
> inheritance; the programmer explicitly specifies the location of the base
> object in the successor. It is strange that this simple and obvious
> opportunity not appeared in the C language.
>
> I propose enhanced (compared with Go) feature of such embedding. We can
> use the existing "inline" keyword (or some other keyword, eg. "embed") to
> indicate the embedded fields.
>
> struct SmallBox {
>   int a, b, c;
> };
>
> struct BigBox {
>  time_t Timestamp;
>  inline SmallBox inlinedBox;
>  std::string Name;
> };
>
> As a result, we can access to the fields of SmallBox both directly and
> through an intermediate name "inlinedBox":
>
> BigBox box;
> box.a = 10; //directly, like inheritance
> box.inlinedBox.b = 10; // using an intermediate name, like aggregation
>
>
>
.... what's wrong with inheritance? I know people tend to believe that using
inheritance for something like this is wrong, but these cases are *exactly*
why C++ has robust support for multiple inheritance, unlike most languages.

--
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/245e65c5-c96d-4366-b616-814606d4ebe9%40isocpp.org.

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

<div dir=3D"ltr">On Wednesday, March 2, 2016 at 8:27:30 AM UTC-5, 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">In Go pr=
ogramming language,=C2=A0there is a feature named &quot;emedding&quot;,=C2=
=A0which is used instead of classic c++-like inheritance.<br>For example:<d=
iv><br><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break=
-word;background-color:rgb(250,250,250)"><code><div><span style=3D"font-siz=
e:12px;vertical-align:baseline;outline:0px;color:rgb(51,51,51);font-weight:=
700;font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-height:22=
..3999996185303px;white-space:pre-wrap"><span style=3D"color:#000">type</spa=
n></span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;C=
ourier New&#39;,monospace;font-size:12px;line-height:22.3999996185303px;whi=
te-space:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#=
000"> </span><span style=3D"color:#606">SmallBox</span><span style=3D"color=
:#000"> </span></span><span style=3D"font-size:12px;vertical-align:baseline=
;outline:0px;color:rgb(51,51,51);font-weight:700;font-family:Menlo,Monaco,&=
#39;Courier New&#39;,monospace;line-height:22.3999996185303px;white-space:p=
re-wrap"><span style=3D"color:#008">struct</span></span><span style=3D"colo=
r:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;fo=
nt-size:12px;line-height:22.3999996185303px;white-space:pre-wrap;background=
-color:rgb(248,248,248)"><span style=3D"color:#000"> </span><span style=3D"=
color:#660">{</span><span style=3D"color:#000"><br></span></span><span styl=
e=3D"font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12p=
x;line-height:22.3999996185303px;white-space:pre-wrap;background-color:rgb(=
248,248,248)"><span style=3D"color:#000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 a</spa=
n><span style=3D"color:#660">,</span><span style=3D"color:#000"> b</span><s=
pan style=3D"color:#660">,</span><span style=3D"color:#000"> c </span></spa=
n><span style=3D"font-size:12px;vertical-align:baseline;outline:0px;color:r=
gb(51,51,51);font-weight:700;font-family:Menlo,Monaco,&#39;Courier New&#39;=
,monospace;line-height:22.3999996185303px;white-space:pre-wrap"><span style=
=3D"color:#008">int</span></span><span style=3D"color:rgb(51,51,51);font-fa=
mily:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-heigh=
t:22.3999996185303px;white-space:pre-wrap;background-color:rgb(248,248,248)=
"><span style=3D"color:#000"><br></span></span><span style=3D"color:rgb(51,=
51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:1=
2px;line-height:22.3999996185303px;white-space:pre-wrap;background-color:rg=
b(248,248,248)"><span style=3D"color:#660">}</span><span style=3D"color:#00=
0"><br></span></span><span style=3D"font-size:12px;vertical-align:baseline;=
outline:0px;color:rgb(51,51,51);font-weight:700;font-family:Menlo,Monaco,&#=
39;Courier New&#39;,monospace;line-height:22.3999996185303px;white-space:pr=
e-wrap"><span style=3D"color:#000">type</span></span><span style=3D"color:r=
gb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-=
size:12px;line-height:22.3999996185303px;white-space:pre-wrap;background-co=
lor:rgb(248,248,248)"><span style=3D"color:#000"> </span><span style=3D"col=
or:#606">BigBox</span><span style=3D"color:#000"> </span></span><span style=
=3D"font-size:12px;vertical-align:baseline;outline:0px;color:rgb(51,51,51);=
font-weight:700;font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;li=
ne-height:22.3999996185303px;white-space:pre-wrap"><span style=3D"color:#00=
8">struct</span></span><span style=3D"color:rgb(51,51,51);font-family:Menlo=
,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22.39999=
96185303px;white-space:pre-wrap;background-color:rgb(248,248,248)"><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span></span><span style=
=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,mono=
space;font-size:12px;line-height:22.3999996185303px;white-space:pre-wrap;ba=
ckground-color:rgb(248,248,248)"><span style=3D"color:#606">Timestamp</span=
><span style=3D"color:#000"> time</span><span style=3D"color:#660">.</span>=
<span style=3D"color:#606">Time</span></span><span style=3D"color:rgb(51,51=
,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12p=
x;line-height:22.3999996185303px;white-space:pre-wrap;background-color:rgb(=
248,248,248)"><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </=
span><span style=3D"color:#606">SmallBox</span><span style=3D"color:#000"> =
=C2=A0</span><span style=3D"color:#800">// &lt;&lt;&lt; embedding</span><sp=
an style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=
=3D"color:#606">Name</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">[]</span></span><span style=3D"font-size:12px;vertical-alig=
n:baseline;outline:0px;color:rgb(51,51,51);font-weight:700;font-family:Menl=
o,Monaco,&#39;Courier New&#39;,monospace;line-height:22.3999996185303px;whi=
te-space:pre-wrap"><span style=3D"color:#008">string</span></span><span sty=
le=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,mo=
nospace;font-size:12px;line-height:22.3999996185303px;white-space:pre-wrap;=
background-color:rgb(248,248,248)"><span style=3D"color:#000"><br></span></=
span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Couri=
er New&#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-s=
pace:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#660"=
>}</span></span><span style=3D"color:#000"><br></span></div></code></div><b=
r>This is very simple and low-level extension of the concept of inheritance=
;=C2=A0the programmer explicitly specifies the location of the base object =
in the successor.=C2=A0It is strange that this simple and obvious opportuni=
ty not appeared in the C language.</div></div><div><br></div><div>I propose=
 enhanced (compared with Go) feature of such embedding.=C2=A0We can use the=
 existing &quot;inline&quot; keyword (or some other keyword, eg. &quot;embe=
d&quot;) to indicate the embedded fields.<br></div><div><br></div><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"><span style=3D"=
color:#008">struct</span><span style=3D"color:#000"> </span><span style=3D"=
color:#606">SmallBox</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 </span><span =
style=3D"color:#008">int</span><span style=3D"color:#000"> a</span><span st=
yle=3D"color:#660">,</span><span style=3D"color:#000"> b</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> c</span><span style=3D"=
color:#660">;</span><span style=3D"color:#000"><br></span><span style=3D"co=
lor:#660">};</span><span style=3D"color:#000"><br><br></span><span style=3D=
"color:#008">struct</span><span style=3D"color:#000"> </span><span style=3D=
"color:#606">BigBox</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0time_t </span><sp=
an style=3D"color:#606">Timestamp</span><span style=3D"color:#660">;</span>=
<span style=3D"color:#000"> <br>=C2=A0</span><span style=3D"color:#008">inl=
ine</span><span style=3D"color:#000"> </span><span style=3D"color:#606">Sma=
llBox</span><span style=3D"color:#000"> inlinedBox</span><span style=3D"col=
or:#660">;</span><span style=3D"color:#000"><br>=C2=A0std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#008">string</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#606">Name</span><span style=
=3D"color:#660">;</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#660">};</span><span style=3D"color:#000"><br></span></font></div=
></code></div><br>As a result, we can access to the fields of=C2=A0SmallBox=
=C2=A0both directly and through an intermediate name &quot;inlinedBox&quot;=
:<br></div><div><br></div><div><div style=3D"border:1px solid rgb(187,187,1=
87);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div><fon=
t color=3D"#660066"><span style=3D"color:#606">BigBox</span><span style=3D"=
color:#000"> box</span><span style=3D"color:#660">;</span><span style=3D"co=
lor:#000"><br>box</span><span style=3D"color:#660">.</span><span style=3D"c=
olor:#000">a </span><span style=3D"color:#660">=3D</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#066">10</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"> </span><span style=3D"color:#800">=
//directly, </span></font><font color=3D"#880000"><span style=3D"color:#800=
">like inheritance</span><span style=3D"color:#000"><br>box</span><span sty=
le=3D"color:#660">.</span><span style=3D"color:#000">inlinedBox</span><span=
 style=3D"color:#660">.</span><span style=3D"color:#000">b </span><span sty=
le=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span style=
=3D"color:#066">10</span><span style=3D"color:#660">;</span><span style=3D"=
color:#000"> </span><span style=3D"color:#800">// </span></font><span style=
=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,255,255=
)"><span style=3D"color:#800">using </span><span style=3D"color:#800">an in=
termediate name, </span></span><span style=3D"color:rgb(136,0,0);font-famil=
y:Arial,Helvetica,sans-serif"><span style=3D"color:#800">like aggregation</=
span></span></div></code></div><br><br></div></div></blockquote><div><br>..=
.. what&#39;s wrong with inheritance? I know people tend to believe that usi=
ng inheritance for something like this is wrong, but these cases are <i>exa=
ctly</i> why C++ has robust support for multiple inheritance, unlike most l=
anguages.<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/245e65c5-c96d-4366-b616-814606d4ebe9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/245e65c5-c96d-4366-b616-814606d4ebe9=
%40isocpp.org</a>.<br />

------=_Part_6305_1116270529.1456926388583--
------=_Part_6304_1134666666.1456926388582--

.


Author: NeoCode <neoprogramming@gmail.com>
Date: Wed, 2 Mar 2016 05:59:34 -0800 (PST)
Raw View
------=_Part_294_2059805163.1456927175054
Content-Type: multipart/alternative;
 boundary="----=_Part_295_1770055624.1456927175054"

------=_Part_295_1770055624.1456927175054
Content-Type: text/plain; charset=UTF-8



On Wednesday, March 2, 2016 at 4:46:29 PM UTC+3, Nicol Bolas wrote:
>
> On Wednesday, March 2, 2016 at 8:27:30 AM UTC-5, NeoCode wrote:
>>
>> In Go programming language, there is a feature named "emedding", which is
>> used instead of classic c++-like inheritance.
>> For example:
>>
>> type SmallBox struct {
>>         a, b, c int
>> }
>> type BigBox struct {
>>         Timestamp time.Time
>>         SmallBox  // <<< embedding
>>         Name []string
>> }
>>
>> This is very simple and low-level extension of the concept of
>> inheritance; the programmer explicitly specifies the location of the base
>> object in the successor. It is strange that this simple and obvious
>> opportunity not appeared in the C language.
>>
>> I propose enhanced (compared with Go) feature of such embedding. We can
>> use the existing "inline" keyword (or some other keyword, eg. "embed") to
>> indicate the embedded fields.
>>
>> struct SmallBox {
>>   int a, b, c;
>> };
>>
>> struct BigBox {
>>  time_t Timestamp;
>>  inline SmallBox inlinedBox;
>>  std::string Name;
>> };
>>
>> As a result, we can access to the fields of SmallBox both directly and
>> through an intermediate name "inlinedBox":
>>
>> BigBox box;
>> box.a = 10; //directly, like inheritance
>> box.inlinedBox.b = 10; // using an intermediate name, like aggregation
>>
>>
>>
> ... what's wrong with inheritance? I know people tend to believe that
> using inheritance for something like this is wrong, but these cases are
> *exactly* why C++ has robust support for multiple inheritance, unlike
> most languages.
>

Nothing wrong with inheritance. It's just an additional opportunity.

--
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/2bbe1861-b3b8-49cf-8405-ab840bd7b5fd%40isocpp.org.

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

<div dir=3D"ltr"><br><br>On Wednesday, March 2, 2016 at 4:46:29 PM UTC+3, N=
icol Bolas wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">On Wednesday, March 2, 2016 at 8:27:30 AM UTC-5, NeoCode wrote:<blockqu=
ote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1=
px #ccc solid;padding-left:1ex"><div dir=3D"ltr">In Go programming language=
,=C2=A0there is a feature named &quot;emedding&quot;,=C2=A0which is used in=
stead of classic c++-like inheritance.<br>For example:<div><br><div><div st=
yle=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-co=
lor:rgb(250,250,250)"><code><div><span style=3D"font-size:12px;vertical-ali=
gn:baseline;outline:0px;color:rgb(51,51,51);font-weight:700;font-family:Men=
lo,Monaco,&#39;Courier New&#39;,monospace;line-height:22.3999996185303px;wh=
ite-space:pre-wrap"><span style=3D"color:#000">type</span></span><span styl=
e=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,mon=
ospace;font-size:12px;line-height:22.3999996185303px;white-space:pre-wrap;b=
ackground-color:rgb(248,248,248)"><span style=3D"color:#000"> </span><span =
style=3D"color:#606">SmallBox</span><span style=3D"color:#000"> </span></sp=
an><span style=3D"font-size:12px;vertical-align:baseline;outline:0px;color:=
rgb(51,51,51);font-weight:700;font-family:Menlo,Monaco,&#39;Courier New&#39=
;,monospace;line-height:22.3999996185303px;white-space:pre-wrap"><span styl=
e=3D"color:#008">struct</span></span><span style=3D"color:rgb(51,51,51);fon=
t-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-h=
eight:22.3999996185303px;white-space:pre-wrap;background-color:rgb(248,248,=
248)"><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span=
><span style=3D"color:#000"><br></span></span><span style=3D"font-family:Me=
nlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22.39=
99996185303px;white-space:pre-wrap;background-color:rgb(248,248,248)"><span=
 style=3D"color:#000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 a</span><span style=3D"co=
lor:#660">,</span><span style=3D"color:#000"> b</span><span style=3D"color:=
#660">,</span><span style=3D"color:#000"> c </span></span><span style=3D"fo=
nt-size:12px;vertical-align:baseline;outline:0px;color:rgb(51,51,51);font-w=
eight:700;font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-hei=
ght:22.3999996185303px;white-space:pre-wrap"><span style=3D"color:#008">int=
</span></span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&=
#39;Courier New&#39;,monospace;font-size:12px;line-height:22.3999996185303p=
x;white-space:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"co=
lor:#000"><br></span></span><span style=3D"color:rgb(51,51,51);font-family:=
Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22.=
3999996185303px;white-space:pre-wrap;background-color:rgb(248,248,248)"><sp=
an style=3D"color:#660">}</span><span style=3D"color:#000"><br></span></spa=
n><span style=3D"font-size:12px;vertical-align:baseline;outline:0px;color:r=
gb(51,51,51);font-weight:700;font-family:Menlo,Monaco,&#39;Courier New&#39;=
,monospace;line-height:22.3999996185303px;white-space:pre-wrap"><span style=
=3D"color:#000">type</span></span><span style=3D"color:rgb(51,51,51);font-f=
amily:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-heig=
ht:22.3999996185303px;white-space:pre-wrap;background-color:rgb(248,248,248=
)"><span style=3D"color:#000"> </span><span style=3D"color:#606">BigBox</sp=
an><span style=3D"color:#000"> </span></span><span style=3D"font-size:12px;=
vertical-align:baseline;outline:0px;color:rgb(51,51,51);font-weight:700;fon=
t-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-height:22.399999=
6185303px;white-space:pre-wrap"><span style=3D"color:#008">struct</span></s=
pan><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courie=
r New&#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-sp=
ace:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#000">=
 </span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span></span><span style=3D"color:rgb(51,51,51=
);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;l=
ine-height:22.3999996185303px;white-space:pre-wrap;background-color:rgb(248=
,248,248)"><span style=3D"color:#606">Timestamp</span><span style=3D"color:=
#000"> time</span><span style=3D"color:#660">.</span><span style=3D"color:#=
606">Time</span></span><span style=3D"color:rgb(51,51,51);font-family:Menlo=
,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22.39999=
96185303px;white-space:pre-wrap;background-color:rgb(248,248,248)"><span st=
yle=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"co=
lor:#606">SmallBox</span><span style=3D"color:#000"> =C2=A0</span><span sty=
le=3D"color:#800">// &lt;&lt;&lt; embedding</span><span style=3D"color:#000=
"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#606">Name</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">[]</span>=
</span><span style=3D"font-size:12px;vertical-align:baseline;outline:0px;co=
lor:rgb(51,51,51);font-weight:700;font-family:Menlo,Monaco,&#39;Courier New=
&#39;,monospace;line-height:22.3999996185303px;white-space:pre-wrap"><span =
style=3D"color:#008">string</span></span><span style=3D"color:rgb(51,51,51)=
;font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;li=
ne-height:22.3999996185303px;white-space:pre-wrap;background-color:rgb(248,=
248,248)"><span style=3D"color:#000"><br></span></span><span style=3D"color=
:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;fon=
t-size:12px;line-height:22.3999996185303px;white-space:pre-wrap;background-=
color:rgb(248,248,248)"><span style=3D"color:#660">}</span></span><span sty=
le=3D"color:#000"><br></span></div></code></div><br>This is very simple and=
 low-level extension of the concept of inheritance;=C2=A0the programmer exp=
licitly specifies the location of the base object in the successor.=C2=A0It=
 is strange that this simple and obvious opportunity not appeared in the C =
language.</div></div><div><br></div><div>I propose enhanced (compared with =
Go) feature of such embedding.=C2=A0We can use the existing &quot;inline&qu=
ot; keyword (or some other keyword, eg. &quot;embed&quot;) to indicate the =
embedded fields.<br></div><div><br></div><div><div style=3D"border:1px soli=
d rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)">=
<code><div><font color=3D"#660066"><span style=3D"color:#008">struct</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#606">SmallBox</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><sp=
an style=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#008">int</s=
pan><span style=3D"color:#000"> a</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> b</span><span style=3D"color:#660">,</span><spa=
n style=3D"color:#000"> c</span><span style=3D"color:#660">;</span><span st=
yle=3D"color:#000"><br></span><span style=3D"color:#660">};</span><span sty=
le=3D"color:#000"><br><br></span><span style=3D"color:#008">struct</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#606">BigBox</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span s=
tyle=3D"color:#000"><br>=C2=A0time_t </span><span style=3D"color:#606">Time=
stamp</span><span style=3D"color:#660">;</span><span style=3D"color:#000"> =
<br>=C2=A0</span><span style=3D"color:#008">inline</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#606">SmallBox</span><span style=3D"c=
olor:#000"> inlinedBox</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"><br>=C2=A0std</span><span style=3D"color:#660">::</span><sp=
an style=3D"color:#008">string</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#606">Name</span><span style=3D"color:#660">;</span><span=
 style=3D"color:#000"><br></span><span style=3D"color:#660">};</span><span =
style=3D"color:#000"><br></span></font></div></code></div><br>As a result, =
we can access to the fields of=C2=A0SmallBox=C2=A0both directly and through=
 an intermediate name &quot;inlinedBox&quot;:<br></div><div><br></div><div>=
<div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;backgr=
ound-color:rgb(250,250,250)"><code><div><font color=3D"#660066"><span style=
=3D"color:#606">BigBox</span><span style=3D"color:#000"> box</span><span st=
yle=3D"color:#660">;</span><span style=3D"color:#000"><br>box</span><span s=
tyle=3D"color:#660">.</span><span style=3D"color:#000">a </span><span style=
=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span style=3D=
"color:#066">10</span><span style=3D"color:#660">;</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#800">//directly, </span></font><font=
 color=3D"#880000"><span style=3D"color:#800">like inheritance</span><span =
style=3D"color:#000"><br>box</span><span style=3D"color:#660">.</span><span=
 style=3D"color:#000">inlinedBox</span><span style=3D"color:#660">.</span><=
span style=3D"color:#000">b </span><span style=3D"color:#660">=3D</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#066">10</span><span s=
tyle=3D"color:#660">;</span><span style=3D"color:#000"> </span><span style=
=3D"color:#800">// </span></font><span style=3D"font-family:Arial,Helvetica=
,sans-serif;background-color:rgb(255,255,255)"><span style=3D"color:#800">u=
sing </span><span style=3D"color:#800">an intermediate name, </span></span>=
<span style=3D"color:rgb(136,0,0);font-family:Arial,Helvetica,sans-serif"><=
span style=3D"color:#800">like aggregation</span></span></div></code></div>=
<br><br></div></div></blockquote><div><br>... what&#39;s wrong with inherit=
ance? I know people tend to believe that using inheritance for something li=
ke this is wrong, but these cases are <i>exactly</i> why C++ has robust sup=
port for multiple inheritance, unlike most languages.<br></div></div></bloc=
kquote><div><br></div><div>Nothing wrong with inheritance. It&#39;s just an=
 additional opportunity.=C2=A0</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/2bbe1861-b3b8-49cf-8405-ab840bd7b5fd%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/2bbe1861-b3b8-49cf-8405-ab840bd7b5fd=
%40isocpp.org</a>.<br />

------=_Part_295_1770055624.1456927175054--
------=_Part_294_2059805163.1456927175054--

.


Author: TONGARI J <tongari95@gmail.com>
Date: Wed, 2 Mar 2016 06:57:51 -0800 (PST)
Raw View
------=_Part_4710_755491452.1456930671711
Content-Type: multipart/alternative;
 boundary="----=_Part_4711_2083531829.1456930671712"

------=_Part_4711_2083531829.1456930671712
Content-Type: text/plain; charset=UTF-8

On Wednesday, March 2, 2016 at 9:46:29 PM UTC+8, Nicol Bolas wrote:
>
> On Wednesday, March 2, 2016 at 8:27:30 AM UTC-5, NeoCode wrote:
>>
>> In Go programming language, there is a feature named "emedding", which is
>> used instead of classic c++-like inheritance.
>> For example:
>>
>> type SmallBox struct {
>>         a, b, c int
>> }
>> type BigBox struct {
>>         Timestamp time.Time
>>         SmallBox  // <<< embedding
>>         Name []string
>> }
>>
>> This is very simple and low-level extension of the concept of
>> inheritance; the programmer explicitly specifies the location of the base
>> object in the successor. It is strange that this simple and obvious
>> opportunity not appeared in the C language.
>>
>> I propose enhanced (compared with Go) feature of such embedding. We can
>> use the existing "inline" keyword (or some other keyword, eg. "embed") to
>> indicate the embedded fields.
>>
>> struct SmallBox {
>>   int a, b, c;
>> };
>>
>> struct BigBox {
>>  time_t Timestamp;
>>  inline SmallBox inlinedBox;
>>  std::string Name;
>> };
>>
>> As a result, we can access to the fields of SmallBox both directly and
>> through an intermediate name "inlinedBox":
>>
>> BigBox box;
>> box.a = 10; //directly, like inheritance
>> box.inlinedBox.b = 10; // using an intermediate name, like aggregation
>>
>>
>>
> ... what's wrong with inheritance? I know people tend to believe that
> using inheritance for something like this is wrong, but these cases are
> *exactly* why C++ has robust support for multiple inheritance, unlike
> most languages.
>

I think it's for object layout. Using inheritance would force you to layout
`SmallBox` before `Timestamp` in the example (unless you make `Timestamp`
another base).

I'm not familiar with Go, but if this is the OP's intent, I'd suggest
taking a step further to make the feature help data packing, e.g.

struct A
{
    uint32_t a1;
    char a2;
};

struct B
{
    uint32_t b1;
    inline A;
    char b2;
};

may allow the size of B to be 12 instead of 16.

--
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/0ee10bc5-b45e-430e-bb08-69a80863cecb%40isocpp.org.

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

<div dir=3D"ltr">On Wednesday, March 2, 2016 at 9:46:29 PM UTC+8, Nicol Bol=
as wrote:<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">On W=
ednesday, March 2, 2016 at 8:27:30 AM UTC-5, NeoCode wrote:<blockquote clas=
s=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc =
solid;padding-left:1ex"><div dir=3D"ltr">In Go programming language,=C2=A0t=
here is a feature named &quot;emedding&quot;,=C2=A0which is used instead of=
 classic c++-like inheritance.<br>For example:<div><br><div><div style=3D"b=
order:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(=
250,250,250)"><code><div><span style=3D"font-size:12px;vertical-align:basel=
ine;outline:0px;color:rgb(51,51,51);font-weight:700;font-family:Menlo,Monac=
o,&#39;Courier New&#39;,monospace;line-height:22.3999996185303px;white-spac=
e:pre-wrap"><span style=3D"color:#000">type</span></span><span style=3D"col=
or:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;f=
ont-size:12px;line-height:22.3999996185303px;white-space:pre-wrap;backgroun=
d-color:rgb(248,248,248)"><span style=3D"color:#000"> </span><span style=3D=
"color:#606">SmallBox</span><span style=3D"color:#000"> </span></span><span=
 style=3D"font-size:12px;vertical-align:baseline;outline:0px;color:rgb(51,5=
1,51);font-weight:700;font-family:Menlo,Monaco,&#39;Courier New&#39;,monosp=
ace;line-height:22.3999996185303px;white-space:pre-wrap"><span style=3D"col=
or:#008">struct</span></span><span style=3D"color:rgb(51,51,51);font-family=
:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22=
..3999996185303px;white-space:pre-wrap;background-color:rgb(248,248,248)"><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span s=
tyle=3D"color:#000"><br></span></span><span style=3D"font-family:Menlo,Mona=
co,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22.3999996185=
303px;white-space:pre-wrap;background-color:rgb(248,248,248)"><span style=
=3D"color:#000">=C2=A0 =C2=A0 =C2=A0 =C2=A0 a</span><span style=3D"color:#6=
60">,</span><span style=3D"color:#000"> b</span><span style=3D"color:#660">=
,</span><span style=3D"color:#000"> c </span></span><span style=3D"font-siz=
e:12px;vertical-align:baseline;outline:0px;color:rgb(51,51,51);font-weight:=
700;font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-height:22=
..3999996185303px;white-space:pre-wrap"><span style=3D"color:#008">int</span=
></span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Co=
urier New&#39;,monospace;font-size:12px;line-height:22.3999996185303px;whit=
e-space:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#0=
00"><br></span></span><span style=3D"color:rgb(51,51,51);font-family:Menlo,=
Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22.399999=
6185303px;white-space:pre-wrap;background-color:rgb(248,248,248)"><span sty=
le=3D"color:#660">}</span><span style=3D"color:#000"><br></span></span><spa=
n style=3D"font-size:12px;vertical-align:baseline;outline:0px;color:rgb(51,=
51,51);font-weight:700;font-family:Menlo,Monaco,&#39;Courier New&#39;,monos=
pace;line-height:22.3999996185303px;white-space:pre-wrap"><span style=3D"co=
lor:#000">type</span></span><span style=3D"color:rgb(51,51,51);font-family:=
Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22.=
3999996185303px;white-space:pre-wrap;background-color:rgb(248,248,248)"><sp=
an style=3D"color:#000"> </span><span style=3D"color:#606">BigBox</span><sp=
an style=3D"color:#000"> </span></span><span style=3D"font-size:12px;vertic=
al-align:baseline;outline:0px;color:rgb(51,51,51);font-weight:700;font-fami=
ly:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-height:22.399999618530=
3px;white-space:pre-wrap"><span style=3D"color:#008">struct</span></span><s=
pan style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&=
#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-space:pr=
e-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 </span></span><span style=3D"color:rgb(51,51,51);font-=
family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-hei=
ght:22.3999996185303px;white-space:pre-wrap;background-color:rgb(248,248,24=
8)"><span style=3D"color:#606">Timestamp</span><span style=3D"color:#000"> =
time</span><span style=3D"color:#660">.</span><span style=3D"color:#606">Ti=
me</span></span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco=
,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22.399999618530=
3px;white-space:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"=
color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#60=
6">SmallBox</span><span style=3D"color:#000"> =C2=A0</span><span style=3D"c=
olor:#800">// &lt;&lt;&lt; embedding</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#606">Name</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">[]</span></span=
><span style=3D"font-size:12px;vertical-align:baseline;outline:0px;color:rg=
b(51,51,51);font-weight:700;font-family:Menlo,Monaco,&#39;Courier New&#39;,=
monospace;line-height:22.3999996185303px;white-space:pre-wrap"><span style=
=3D"color:#008">string</span></span><span style=3D"color:rgb(51,51,51);font=
-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-he=
ight:22.3999996185303px;white-space:pre-wrap;background-color:rgb(248,248,2=
48)"><span style=3D"color:#000"><br></span></span><span style=3D"color:rgb(=
51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-siz=
e:12px;line-height:22.3999996185303px;white-space:pre-wrap;background-color=
:rgb(248,248,248)"><span style=3D"color:#660">}</span></span><span style=3D=
"color:#000"><br></span></div></code></div><br>This is very simple and low-=
level extension of the concept of inheritance;=C2=A0the programmer explicit=
ly specifies the location of the base object in the successor.=C2=A0It is s=
trange that this simple and obvious opportunity not appeared in the C langu=
age.</div></div><div><br></div><div>I propose enhanced (compared with Go) f=
eature of such embedding.=C2=A0We can use the existing &quot;inline&quot; k=
eyword (or some other keyword, eg. &quot;embed&quot;) to indicate the embed=
ded fields.<br></div><div><br></div><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"><span style=3D"color:#008">struct</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#606">SmallBox</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span st=
yle=3D"color:#000"><br>=C2=A0 </span><span style=3D"color:#008">int</span><=
span style=3D"color:#000"> a</span><span style=3D"color:#660">,</span><span=
 style=3D"color:#000"> b</span><span style=3D"color:#660">,</span><span sty=
le=3D"color:#000"> c</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#660">};</span><span style=
=3D"color:#000"><br><br></span><span style=3D"color:#008">struct</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#606">BigBox</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span sty=
le=3D"color:#000"><br>=C2=A0time_t </span><span style=3D"color:#606">Timest=
amp</span><span style=3D"color:#660">;</span><span style=3D"color:#000"> <b=
r>=C2=A0</span><span style=3D"color:#008">inline</span><span style=3D"color=
:#000"> </span><span style=3D"color:#606">SmallBox</span><span style=3D"col=
or:#000"> inlinedBox</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"><br>=C2=A0std</span><span style=3D"color:#660">::</span><sp=
an style=3D"color:#008">string</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#606">Name</span><span style=3D"color:#660">;</span><span=
 style=3D"color:#000"><br></span><span style=3D"color:#660">};</span><span =
style=3D"color:#000"><br></span></font></div></code></div><br>As a result, =
we can access to the fields of=C2=A0SmallBox=C2=A0both directly and through=
 an intermediate name &quot;inlinedBox&quot;:<br></div><div><br></div><div>=
<div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;backgr=
ound-color:rgb(250,250,250)"><code><div><font color=3D"#660066"><span style=
=3D"color:#606">BigBox</span><span style=3D"color:#000"> box</span><span st=
yle=3D"color:#660">;</span><span style=3D"color:#000"><br>box</span><span s=
tyle=3D"color:#660">.</span><span style=3D"color:#000">a </span><span style=
=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span style=3D=
"color:#066">10</span><span style=3D"color:#660">;</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#800">//directly, </span></font><font=
 color=3D"#880000"><span style=3D"color:#800">like inheritance</span><span =
style=3D"color:#000"><br>box</span><span style=3D"color:#660">.</span><span=
 style=3D"color:#000">inlinedBox</span><span style=3D"color:#660">.</span><=
span style=3D"color:#000">b </span><span style=3D"color:#660">=3D</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#066">10</span><span s=
tyle=3D"color:#660">;</span><span style=3D"color:#000"> </span><span style=
=3D"color:#800">// </span></font><span style=3D"font-family:Arial,Helvetica=
,sans-serif;background-color:rgb(255,255,255)"><span style=3D"color:#800">u=
sing </span><span style=3D"color:#800">an intermediate name, </span></span>=
<span style=3D"color:rgb(136,0,0);font-family:Arial,Helvetica,sans-serif"><=
span style=3D"color:#800">like aggregation</span></span></div></code></div>=
<br><br></div></div></blockquote><div><br>... what&#39;s wrong with inherit=
ance? I know people tend to believe that using inheritance for something li=
ke this is wrong, but these cases are <i>exactly</i> why C++ has robust sup=
port for multiple inheritance, unlike most languages.<br></div></div></bloc=
kquote><div><br></div><div style=3D"font-family: arial, sans-serif; font-si=
ze: small;">I think it&#39;s for object layout. Using inheritance would for=
ce you to layout `SmallBox` before `Timestamp` in the example (unless you m=
ake `Timestamp` another base).</div><div style=3D"font-family: arial, sans-=
serif; font-size: small;"><br></div><div style=3D"font-family: arial, sans-=
serif; font-size: small;">I&#39;m not familiar with Go, but if this is the =
OP&#39;s intent, I&#39;d suggest taking a step further to make the feature =
help data packing, e.g.</div><div style=3D"font-family: arial, sans-serif; =
font-size: small;"><br></div><div style=3D"font-family: arial, sans-serif; =
font-size: small;"><div class=3D"prettyprint" style=3D"border: 1px solid rg=
b(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250, 25=
0);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> A<br></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 =C2=A0 uint32_t a1</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">char</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> a2</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><span style=3D"color: #660;" class=3D"=
styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> B<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 uint32_t b1</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">inline</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> A</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 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">ch=
ar</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> b2</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">};</span></div></code></div>=
<div><br></div></div><div><span style=3D"font-family: arial, sans-serif; fo=
nt-size: small;">may allow the size of B to be 12 instead of 16.</span>=C2=
=A0</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/0ee10bc5-b45e-430e-bb08-69a80863cecb%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0ee10bc5-b45e-430e-bb08-69a80863cecb=
%40isocpp.org</a>.<br />

------=_Part_4711_2083531829.1456930671712--
------=_Part_4710_755491452.1456930671711--

.


Author: Giovanni Piero Deretta <gpderetta@gmail.com>
Date: Wed, 2 Mar 2016 07:11:34 -0800 (PST)
Raw View
------=_Part_6327_290501325.1456931494651
Content-Type: multipart/alternative;
 boundary="----=_Part_6328_1560416818.1456931494652"

------=_Part_6328_1560416818.1456931494652
Content-Type: text/plain; charset=UTF-8

On Wednesday, March 2, 2016 at 2:57:51 PM UTC, TONGARI J wrote:
>
> On Wednesday, March 2, 2016 at 9:46:29 PM UTC+8, Nicol Bolas wrote:
>>
>> On Wednesday, March 2, 2016 at 8:27:30 AM UTC-5, NeoCode wrote:
>>>
>>> In Go programming language, there is a feature named "emedding", which
>>> is used instead of classic c++-like inheritance.
>>> For example:
>>>
>>> type SmallBox struct {
>>>         a, b, c int
>>> }
>>> type BigBox struct {
>>>         Timestamp time.Time
>>>         SmallBox  // <<< embedding
>>>         Name []string
>>> }
>>>
>>> This is very simple and low-level extension of the concept of
>>> inheritance; the programmer explicitly specifies the location of the base
>>> object in the successor. It is strange that this simple and obvious
>>> opportunity not appeared in the C language.
>>>
>>> I propose enhanced (compared with Go) feature of such embedding. We can
>>> use the existing "inline" keyword (or some other keyword, eg. "embed") to
>>> indicate the embedded fields.
>>>
>>> struct SmallBox {
>>>   int a, b, c;
>>> };
>>>
>>> struct BigBox {
>>>  time_t Timestamp;
>>>  inline SmallBox inlinedBox;
>>>  std::string Name;
>>> };
>>>
>>> As a result, we can access to the fields of SmallBox both directly and
>>> through an intermediate name "inlinedBox":
>>>
>>> BigBox box;
>>> box.a = 10; //directly, like inheritance
>>> box.inlinedBox.b = 10; // using an intermediate name, like aggregation
>>>
>>>
>>>
>> ... what's wrong with inheritance? I know people tend to believe that
>> using inheritance for something like this is wrong, but these cases are
>> *exactly* why C++ has robust support for multiple inheritance, unlike
>> most languages.
>>
>
> I think it's for object layout. Using inheritance would force you to
> layout `SmallBox` before `Timestamp` in the example (unless you make
> `Timestamp` another base).
>
>
Also in many cases will prevent the object from being a standard layout
type.

-- gpd

--
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/357de2ac-1b24-48bb-a99d-1b9ede35d142%40isocpp.org.

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

<div dir=3D"ltr">On Wednesday, March 2, 2016 at 2:57:51 PM UTC, TONGARI J 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">On Wedne=
sday, March 2, 2016 at 9:46:29 PM UTC+8, Nicol Bolas wrote:<blockquote clas=
s=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc =
solid;padding-left:1ex"><div dir=3D"ltr">On Wednesday, March 2, 2016 at 8:2=
7:30 AM UTC-5, NeoCode wrote:<blockquote class=3D"gmail_quote" style=3D"mar=
gin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div d=
ir=3D"ltr">In Go programming language,=C2=A0there is a feature named &quot;=
emedding&quot;,=C2=A0which is used instead of classic c++-like inheritance.=
<br>For example:<div><br><div><div style=3D"border:1px solid rgb(187,187,18=
7);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div><span=
 style=3D"font-size:12px;vertical-align:baseline;outline:0px;color:rgb(51,5=
1,51);font-weight:700;font-family:Menlo,Monaco,&#39;Courier New&#39;,monosp=
ace;line-height:22.3999996185303px;white-space:pre-wrap"><span style=3D"col=
or:#000">type</span></span><span style=3D"color:rgb(51,51,51);font-family:M=
enlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22.3=
999996185303px;white-space:pre-wrap;background-color:rgb(248,248,248)"><spa=
n style=3D"color:#000"> </span><span style=3D"color:#606">SmallBox</span><s=
pan style=3D"color:#000"> </span></span><span style=3D"font-size:12px;verti=
cal-align:baseline;outline:0px;color:rgb(51,51,51);font-weight:700;font-fam=
ily:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-height:22.39999961853=
03px;white-space:pre-wrap"><span style=3D"color:#008">struct</span></span><=
span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New=
&#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-space:p=
re-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">{</span><span style=3D"color:#000"><br></span=
></span><span style=3D"font-family:Menlo,Monaco,&#39;Courier New&#39;,monos=
pace;font-size:12px;line-height:22.3999996185303px;white-space:pre-wrap;bac=
kground-color:rgb(248,248,248)"><span style=3D"color:#000">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 a</span><span style=3D"color:#660">,</span><span style=3D"col=
or:#000"> b</span><span style=3D"color:#660">,</span><span style=3D"color:#=
000"> c </span></span><span style=3D"font-size:12px;vertical-align:baseline=
;outline:0px;color:rgb(51,51,51);font-weight:700;font-family:Menlo,Monaco,&=
#39;Courier New&#39;,monospace;line-height:22.3999996185303px;white-space:p=
re-wrap"><span style=3D"color:#008">int</span></span><span style=3D"color:r=
gb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-=
size:12px;line-height:22.3999996185303px;white-space:pre-wrap;background-co=
lor:rgb(248,248,248)"><span style=3D"color:#000"><br></span></span><span st=
yle=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,m=
onospace;font-size:12px;line-height:22.3999996185303px;white-space:pre-wrap=
;background-color:rgb(248,248,248)"><span style=3D"color:#660">}</span><spa=
n style=3D"color:#000"><br></span></span><span style=3D"font-size:12px;vert=
ical-align:baseline;outline:0px;color:rgb(51,51,51);font-weight:700;font-fa=
mily:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-height:22.3999996185=
303px;white-space:pre-wrap"><span style=3D"color:#000">type</span></span><s=
pan style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&=
#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-space:pr=
e-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#000"> </spa=
n><span style=3D"color:#606">BigBox</span><span style=3D"color:#000"> </spa=
n></span><span style=3D"font-size:12px;vertical-align:baseline;outline:0px;=
color:rgb(51,51,51);font-weight:700;font-family:Menlo,Monaco,&#39;Courier N=
ew&#39;,monospace;line-height:22.3999996185303px;white-space:pre-wrap"><spa=
n style=3D"color:#008">struct</span></span><span style=3D"color:rgb(51,51,5=
1);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;=
line-height:22.3999996185303px;white-space:pre-wrap;background-color:rgb(24=
8,248,248)"><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span></=
span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Couri=
er New&#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-s=
pace:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#606"=
>Timestamp</span><span style=3D"color:#000"> time</span><span style=3D"colo=
r:#660">.</span><span style=3D"color:#606">Time</span></span><span style=3D=
"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospa=
ce;font-size:12px;line-height:22.3999996185303px;white-space:pre-wrap;backg=
round-color:rgb(248,248,248)"><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 </span><span style=3D"color:#606">SmallBox</span><span style=
=3D"color:#000"> =C2=A0</span><span style=3D"color:#800">// &lt;&lt;&lt; em=
bedding</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </=
span><span style=3D"color:#606">Name</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">[]</span></span><span style=3D"font-size:12px=
;vertical-align:baseline;outline:0px;color:rgb(51,51,51);font-weight:700;fo=
nt-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-height:22.39999=
96185303px;white-space:pre-wrap"><span style=3D"color:#008">string</span></=
span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Couri=
er New&#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-s=
pace:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#000"=
><br></span></span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Mon=
aco,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22.399999618=
5303px;white-space:pre-wrap;background-color:rgb(248,248,248)"><span style=
=3D"color:#660">}</span></span><span style=3D"color:#000"><br></span></div>=
</code></div><br>This is very simple and low-level extension of the concept=
 of inheritance;=C2=A0the programmer explicitly specifies the location of t=
he base object in the successor.=C2=A0It is strange that this simple and ob=
vious opportunity not appeared in the C language.</div></div><div><br></div=
><div>I propose enhanced (compared with Go) feature of such embedding.=C2=
=A0We can use the existing &quot;inline&quot; keyword (or some other keywor=
d, eg. &quot;embed&quot;) to indicate the embedded fields.<br></div><div><b=
r></div><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:brea=
k-word;background-color:rgb(250,250,250)"><code><div><font color=3D"#660066=
"><span style=3D"color:#008">struct</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#606">SmallBox</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=
=A0 </span><span style=3D"color:#008">int</span><span style=3D"color:#000">=
 a</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> b</=
span><span style=3D"color:#660">,</span><span style=3D"color:#000"> c</span=
><span style=3D"color:#660">;</span><span style=3D"color:#000"><br></span><=
span style=3D"color:#660">};</span><span style=3D"color:#000"><br><br></spa=
n><span style=3D"color:#008">struct</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#606">BigBox</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0t=
ime_t </span><span style=3D"color:#606">Timestamp</span><span style=3D"colo=
r:#660">;</span><span style=3D"color:#000"> <br>=C2=A0</span><span style=3D=
"color:#008">inline</span><span style=3D"color:#000"> </span><span style=3D=
"color:#606">SmallBox</span><span style=3D"color:#000"> inlinedBox</span><s=
pan style=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=A0std</=
span><span style=3D"color:#660">::</span><span style=3D"color:#008">string<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#606">Name</s=
pan><span style=3D"color:#660">;</span><span style=3D"color:#000"><br></spa=
n><span style=3D"color:#660">};</span><span style=3D"color:#000"><br></span=
></font></div></code></div><br>As a result, we can access to the fields of=
=C2=A0SmallBox=C2=A0both directly and through an intermediate name &quot;in=
linedBox&quot;:<br></div><div><br></div><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"><span style=3D"color:#606">BigBox</span><=
span style=3D"color:#000"> box</span><span style=3D"color:#660">;</span><sp=
an style=3D"color:#000"><br>box</span><span style=3D"color:#660">.</span><s=
pan style=3D"color:#000">a </span><span style=3D"color:#660">=3D</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#066">10</span><span st=
yle=3D"color:#660">;</span><span style=3D"color:#000"> </span><span style=
=3D"color:#800">//directly, </span></font><font color=3D"#880000"><span sty=
le=3D"color:#800">like inheritance</span><span style=3D"color:#000"><br>box=
</span><span style=3D"color:#660">.</span><span style=3D"color:#000">inline=
dBox</span><span style=3D"color:#660">.</span><span style=3D"color:#000">b =
</span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#066">10</span><span style=3D"color:#660">;</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#800">// </span></f=
ont><span style=3D"font-family:Arial,Helvetica,sans-serif;background-color:=
rgb(255,255,255)"><span style=3D"color:#800">using </span><span style=3D"co=
lor:#800">an intermediate name, </span></span><span style=3D"color:rgb(136,=
0,0);font-family:Arial,Helvetica,sans-serif"><span style=3D"color:#800">lik=
e aggregation</span></span></div></code></div><br><br></div></div></blockqu=
ote><div><br>... what&#39;s wrong with inheritance? I know people tend to b=
elieve that using inheritance for something like this is wrong, but these c=
ases are <i>exactly</i> why C++ has robust support for multiple inheritance=
, unlike most languages.<br></div></div></blockquote><div><br></div><div st=
yle=3D"font-family:arial,sans-serif;font-size:small">I think it&#39;s for o=
bject layout. Using inheritance would force you to layout `SmallBox` before=
 `Timestamp` in the example (unless you make `Timestamp` another base).</di=
v><div style=3D"font-family:arial,sans-serif;font-size:small"><br></div></d=
iv></blockquote><div><br>Also in many cases will prevent the object from be=
ing a standard layout type. <br><br>-- gpd<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/357de2ac-1b24-48bb-a99d-1b9ede35d142%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/357de2ac-1b24-48bb-a99d-1b9ede35d142=
%40isocpp.org</a>.<br />

------=_Part_6328_1560416818.1456931494652--
------=_Part_6327_290501325.1456931494651--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Wed, 2 Mar 2016 11:25:16 -0800 (PST)
Raw View
------=_Part_24_708486682.1456946716143
Content-Type: multipart/alternative;
 boundary="----=_Part_25_454662279.1456946716143"

------=_Part_25_454662279.1456946716143
Content-Type: text/plain; charset=UTF-8

On Wednesday, March 2, 2016 at 8:59:35 AM UTC-5, NeoCode wrote:
>
> On Wednesday, March 2, 2016 at 4:46:29 PM UTC+3, Nicol Bolas wrote:
>>
>> On Wednesday, March 2, 2016 at 8:27:30 AM UTC-5, NeoCode wrote:
>>>
>>> In Go programming language, there is a feature named "emedding", which
>>> is used instead of classic c++-like inheritance.
>>> For example:
>>>
>>> type SmallBox struct {
>>>         a, b, c int
>>> }
>>> type BigBox struct {
>>>         Timestamp time.Time
>>>         SmallBox  // <<< embedding
>>>         Name []string
>>> }
>>>
>>> This is very simple and low-level extension of the concept of
>>> inheritance; the programmer explicitly specifies the location of the base
>>> object in the successor. It is strange that this simple and obvious
>>> opportunity not appeared in the C language.
>>>
>>> I propose enhanced (compared with Go) feature of such embedding. We can
>>> use the existing "inline" keyword (or some other keyword, eg. "embed") to
>>> indicate the embedded fields.
>>>
>>> struct SmallBox {
>>>   int a, b, c;
>>> };
>>>
>>> struct BigBox {
>>>  time_t Timestamp;
>>>  inline SmallBox inlinedBox;
>>>  std::string Name;
>>> };
>>>
>>> As a result, we can access to the fields of SmallBox both directly and
>>> through an intermediate name "inlinedBox":
>>>
>>> BigBox box;
>>> box.a = 10; //directly, like inheritance
>>> box.inlinedBox.b = 10; // using an intermediate name, like aggregation
>>>
>>>
>>>
>> ... what's wrong with inheritance? I know people tend to believe that
>> using inheritance for something like this is wrong, but these cases are
>> *exactly* why C++ has robust support for multiple inheritance, unlike
>> most languages.
>>
>
> Nothing wrong with inheritance. It's just an additional opportunity.
>

"An additional opportunity" to do what, exactly? If we already have a way
to do what you're trying to do, then we don't need to add a new feature to
the language. And if there's something you're trying to do that *cannot* be
done currently, then that should be used as justification for the addition.
As well as some reason to believe that lacking this functionality is a
problem of significant importance that it requires a language feature to
solve.

"Because <insert language here> has that feature" is not a good enough
reason to add the feature to C++.

--
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/0b4a0bab-fa39-4214-b6dd-51ffdfb078e8%40isocpp.org.

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

<div dir=3D"ltr">On Wednesday, March 2, 2016 at 8:59:35 AM UTC-5, 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">On Wedne=
sday, March 2, 2016 at 4:46:29 PM UTC+3, Nicol Bolas wrote:<blockquote clas=
s=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc =
solid;padding-left:1ex"><div dir=3D"ltr">On Wednesday, March 2, 2016 at 8:2=
7:30 AM UTC-5, NeoCode wrote:<blockquote class=3D"gmail_quote" style=3D"mar=
gin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div d=
ir=3D"ltr">In Go programming language,=C2=A0there is a feature named &quot;=
emedding&quot;,=C2=A0which is used instead of classic c++-like inheritance.=
<br>For example:<div><br><div><div style=3D"border:1px solid rgb(187,187,18=
7);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div><span=
 style=3D"font-size:12px;vertical-align:baseline;outline:0px;color:rgb(51,5=
1,51);font-weight:700;font-family:Menlo,Monaco,&#39;Courier New&#39;,monosp=
ace;line-height:22.3999996185303px;white-space:pre-wrap"><span style=3D"col=
or:#000">type</span></span><span style=3D"color:rgb(51,51,51);font-family:M=
enlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22.3=
999996185303px;white-space:pre-wrap;background-color:rgb(248,248,248)"><spa=
n style=3D"color:#000"> </span><span style=3D"color:#606">SmallBox</span><s=
pan style=3D"color:#000"> </span></span><span style=3D"font-size:12px;verti=
cal-align:baseline;outline:0px;color:rgb(51,51,51);font-weight:700;font-fam=
ily:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-height:22.39999961853=
03px;white-space:pre-wrap"><span style=3D"color:#008">struct</span></span><=
span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New=
&#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-space:p=
re-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">{</span><span style=3D"color:#000"><br></span=
></span><span style=3D"font-family:Menlo,Monaco,&#39;Courier New&#39;,monos=
pace;font-size:12px;line-height:22.3999996185303px;white-space:pre-wrap;bac=
kground-color:rgb(248,248,248)"><span style=3D"color:#000">=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 a</span><span style=3D"color:#660">,</span><span style=3D"col=
or:#000"> b</span><span style=3D"color:#660">,</span><span style=3D"color:#=
000"> c </span></span><span style=3D"font-size:12px;vertical-align:baseline=
;outline:0px;color:rgb(51,51,51);font-weight:700;font-family:Menlo,Monaco,&=
#39;Courier New&#39;,monospace;line-height:22.3999996185303px;white-space:p=
re-wrap"><span style=3D"color:#008">int</span></span><span style=3D"color:r=
gb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-=
size:12px;line-height:22.3999996185303px;white-space:pre-wrap;background-co=
lor:rgb(248,248,248)"><span style=3D"color:#000"><br></span></span><span st=
yle=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,m=
onospace;font-size:12px;line-height:22.3999996185303px;white-space:pre-wrap=
;background-color:rgb(248,248,248)"><span style=3D"color:#660">}</span><spa=
n style=3D"color:#000"><br></span></span><span style=3D"font-size:12px;vert=
ical-align:baseline;outline:0px;color:rgb(51,51,51);font-weight:700;font-fa=
mily:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-height:22.3999996185=
303px;white-space:pre-wrap"><span style=3D"color:#000">type</span></span><s=
pan style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&=
#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-space:pr=
e-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#000"> </spa=
n><span style=3D"color:#606">BigBox</span><span style=3D"color:#000"> </spa=
n></span><span style=3D"font-size:12px;vertical-align:baseline;outline:0px;=
color:rgb(51,51,51);font-weight:700;font-family:Menlo,Monaco,&#39;Courier N=
ew&#39;,monospace;line-height:22.3999996185303px;white-space:pre-wrap"><spa=
n style=3D"color:#008">struct</span></span><span style=3D"color:rgb(51,51,5=
1);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;=
line-height:22.3999996185303px;white-space:pre-wrap;background-color:rgb(24=
8,248,248)"><span style=3D"color:#000"> </span><span style=3D"color:#660">{=
</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span></=
span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Couri=
er New&#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-s=
pace:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#606"=
>Timestamp</span><span style=3D"color:#000"> time</span><span style=3D"colo=
r:#660">.</span><span style=3D"color:#606">Time</span></span><span style=3D=
"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospa=
ce;font-size:12px;line-height:22.3999996185303px;white-space:pre-wrap;backg=
round-color:rgb(248,248,248)"><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 </span><span style=3D"color:#606">SmallBox</span><span style=
=3D"color:#000"> =C2=A0</span><span style=3D"color:#800">// &lt;&lt;&lt; em=
bedding</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </=
span><span style=3D"color:#606">Name</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">[]</span></span><span style=3D"font-size:12px=
;vertical-align:baseline;outline:0px;color:rgb(51,51,51);font-weight:700;fo=
nt-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-height:22.39999=
96185303px;white-space:pre-wrap"><span style=3D"color:#008">string</span></=
span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Couri=
er New&#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-s=
pace:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#000"=
><br></span></span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Mon=
aco,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22.399999618=
5303px;white-space:pre-wrap;background-color:rgb(248,248,248)"><span style=
=3D"color:#660">}</span></span><span style=3D"color:#000"><br></span></div>=
</code></div><br>This is very simple and low-level extension of the concept=
 of inheritance;=C2=A0the programmer explicitly specifies the location of t=
he base object in the successor.=C2=A0It is strange that this simple and ob=
vious opportunity not appeared in the C language.</div></div><div><br></div=
><div>I propose enhanced (compared with Go) feature of such embedding.=C2=
=A0We can use the existing &quot;inline&quot; keyword (or some other keywor=
d, eg. &quot;embed&quot;) to indicate the embedded fields.<br></div><div><b=
r></div><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:brea=
k-word;background-color:rgb(250,250,250)"><code><div><font color=3D"#660066=
"><span style=3D"color:#008">struct</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#606">SmallBox</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=
=A0 </span><span style=3D"color:#008">int</span><span style=3D"color:#000">=
 a</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> b</=
span><span style=3D"color:#660">,</span><span style=3D"color:#000"> c</span=
><span style=3D"color:#660">;</span><span style=3D"color:#000"><br></span><=
span style=3D"color:#660">};</span><span style=3D"color:#000"><br><br></spa=
n><span style=3D"color:#008">struct</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#606">BigBox</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0t=
ime_t </span><span style=3D"color:#606">Timestamp</span><span style=3D"colo=
r:#660">;</span><span style=3D"color:#000"> <br>=C2=A0</span><span style=3D=
"color:#008">inline</span><span style=3D"color:#000"> </span><span style=3D=
"color:#606">SmallBox</span><span style=3D"color:#000"> inlinedBox</span><s=
pan style=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=A0std</=
span><span style=3D"color:#660">::</span><span style=3D"color:#008">string<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#606">Name</s=
pan><span style=3D"color:#660">;</span><span style=3D"color:#000"><br></spa=
n><span style=3D"color:#660">};</span><span style=3D"color:#000"><br></span=
></font></div></code></div><br>As a result, we can access to the fields of=
=C2=A0SmallBox=C2=A0both directly and through an intermediate name &quot;in=
linedBox&quot;:<br></div><div><br></div><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"><span style=3D"color:#606">BigBox</span><=
span style=3D"color:#000"> box</span><span style=3D"color:#660">;</span><sp=
an style=3D"color:#000"><br>box</span><span style=3D"color:#660">.</span><s=
pan style=3D"color:#000">a </span><span style=3D"color:#660">=3D</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#066">10</span><span st=
yle=3D"color:#660">;</span><span style=3D"color:#000"> </span><span style=
=3D"color:#800">//directly, </span></font><font color=3D"#880000"><span sty=
le=3D"color:#800">like inheritance</span><span style=3D"color:#000"><br>box=
</span><span style=3D"color:#660">.</span><span style=3D"color:#000">inline=
dBox</span><span style=3D"color:#660">.</span><span style=3D"color:#000">b =
</span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#066">10</span><span style=3D"color:#660">;</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#800">// </span></f=
ont><span style=3D"font-family:Arial,Helvetica,sans-serif;background-color:=
rgb(255,255,255)"><span style=3D"color:#800">using </span><span style=3D"co=
lor:#800">an intermediate name, </span></span><span style=3D"color:rgb(136,=
0,0);font-family:Arial,Helvetica,sans-serif"><span style=3D"color:#800">lik=
e aggregation</span></span></div></code></div><br><br></div></div></blockqu=
ote><div><br>... what&#39;s wrong with inheritance? I know people tend to b=
elieve that using inheritance for something like this is wrong, but these c=
ases are <i>exactly</i> why C++ has robust support for multiple inheritance=
, unlike most languages.<br></div></div></blockquote><div><br></div><div>No=
thing wrong with inheritance. It&#39;s just an additional opportunity.</div=
></div></blockquote><div><br>&quot;An additional opportunity&quot; to do wh=
at, exactly? If we already have a way to do what you&#39;re trying to do, t=
hen we don&#39;t need to add a new feature to the language. And if there&#3=
9;s something you&#39;re trying to do that <i>cannot</i> be done currently,=
 then that should be used as justification for the addition. As well as som=
e reason to believe that lacking this functionality is a problem of signifi=
cant importance that it requires a language feature to solve.<br><br>&quot;=
Because &lt;insert language here&gt; has that feature&quot; is not a good e=
nough reason to add the feature to C++.<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/0b4a0bab-fa39-4214-b6dd-51ffdfb078e8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0b4a0bab-fa39-4214-b6dd-51ffdfb078e8=
%40isocpp.org</a>.<br />

------=_Part_25_454662279.1456946716143--
------=_Part_24_708486682.1456946716143--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Wed, 2 Mar 2016 11:33:53 -0800 (PST)
Raw View
------=_Part_6719_1061628349.1456947233712
Content-Type: multipart/alternative;
 boundary="----=_Part_6720_469535419.1456947233713"

------=_Part_6720_469535419.1456947233713
Content-Type: text/plain; charset=UTF-8



On Wednesday, March 2, 2016 at 9:57:51 AM UTC-5, TONGARI J wrote:
>
> On Wednesday, March 2, 2016 at 9:46:29 PM UTC+8, Nicol Bolas wrote:
>>
>> On Wednesday, March 2, 2016 at 8:27:30 AM UTC-5, NeoCode wrote:
>>>
>>> In Go programming language, there is a feature named "emedding", which
>>> is used instead of classic c++-like inheritance.
>>> For example:
>>>
>>> type SmallBox struct {
>>>         a, b, c int
>>> }
>>> type BigBox struct {
>>>         Timestamp time.Time
>>>         SmallBox  // <<< embedding
>>>         Name []string
>>> }
>>>
>>> This is very simple and low-level extension of the concept of
>>> inheritance; the programmer explicitly specifies the location of the base
>>> object in the successor. It is strange that this simple and obvious
>>> opportunity not appeared in the C language.
>>>
>>> I propose enhanced (compared with Go) feature of such embedding. We can
>>> use the existing "inline" keyword (or some other keyword, eg. "embed") to
>>> indicate the embedded fields.
>>>
>>> struct SmallBox {
>>>   int a, b, c;
>>> };
>>>
>>> struct BigBox {
>>>  time_t Timestamp;
>>>  inline SmallBox inlinedBox;
>>>  std::string Name;
>>> };
>>>
>>> As a result, we can access to the fields of SmallBox both directly and
>>> through an intermediate name "inlinedBox":
>>>
>>> BigBox box;
>>> box.a = 10; //directly, like inheritance
>>> box.inlinedBox.b = 10; // using an intermediate name, like aggregation
>>>
>>>
>>>
>> ... what's wrong with inheritance? I know people tend to believe that
>> using inheritance for something like this is wrong, but these cases are
>> *exactly* why C++ has robust support for multiple inheritance, unlike
>> most languages.
>>
>
> I think it's for object layout. Using inheritance would force you to
> layout `SmallBox` before `Timestamp` in the example (unless you make
> `Timestamp` another base).
>
> I'm not familiar with Go, but if this is the OP's intent, I'd suggest
> taking a step further to make the feature help data packing, e.g.
>
> struct A
> {
>     uint32_t a1;
>     char a2;
> };
>
> struct B
> {
>     uint32_t b1;
>     inline A;
>     char b2;
> };
>
> may allow the size of B to be 12 instead of 16.
>

So what you want isn't a type `A` at all; it's a named bundle of
declarations that could be inserted into some other type. After all, `B`
doesn't actually contain the type `A`; it contains some declarations that
`A` provided.

It seems to me that this is something that ought to be established at the
time that `A` is defined. Along with rules about what kinds of things
you're allowed and forbidden from putting into them (virtual functions,
etc).

Personally, I don't see the need for such a thing. Or at least, not in the
way you's talking about.

--
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/209f4408-b229-4d6d-a568-f0d9d9f9d3fb%40isocpp.org.

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

<div dir=3D"ltr"><br><br>On Wednesday, March 2, 2016 at 9:57:51 AM UTC-5, T=
ONGARI J wrote:<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=
">On Wednesday, March 2, 2016 at 9:46:29 PM UTC+8, Nicol Bolas wrote:<block=
quote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">On Wednesday, March 2, 2=
016 at 8:27:30 AM UTC-5, NeoCode wrote:<blockquote class=3D"gmail_quote" st=
yle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1=
ex"><div dir=3D"ltr">In Go programming language,=C2=A0there is a feature na=
med &quot;emedding&quot;,=C2=A0which is used instead of classic c++-like in=
heritance.<br>For example:<div><br><div><div style=3D"border:1px solid rgb(=
187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code>=
<div><span style=3D"font-size:12px;vertical-align:baseline;outline:0px;colo=
r:rgb(51,51,51);font-weight:700;font-family:Menlo,Monaco,&#39;Courier New&#=
39;,monospace;line-height:22.3999996185303px;white-space:pre-wrap"><span st=
yle=3D"color:#000">type</span></span><span style=3D"color:rgb(51,51,51);fon=
t-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-h=
eight:22.3999996185303px;white-space:pre-wrap;background-color:rgb(248,248,=
248)"><span style=3D"color:#000"> </span><span style=3D"color:#606">SmallBo=
x</span><span style=3D"color:#000"> </span></span><span style=3D"font-size:=
12px;vertical-align:baseline;outline:0px;color:rgb(51,51,51);font-weight:70=
0;font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-height:22.3=
999996185303px;white-space:pre-wrap"><span style=3D"color:#008">struct</spa=
n></span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;C=
ourier New&#39;,monospace;font-size:12px;line-height:22.3999996185303px;whi=
te-space:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#=
000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000">=
<br></span></span><span style=3D"font-family:Menlo,Monaco,&#39;Courier New&=
#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-space:pr=
e-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#000">=C2=A0=
 =C2=A0 =C2=A0 =C2=A0 a</span><span style=3D"color:#660">,</span><span styl=
e=3D"color:#000"> b</span><span style=3D"color:#660">,</span><span style=3D=
"color:#000"> c </span></span><span style=3D"font-size:12px;vertical-align:=
baseline;outline:0px;color:rgb(51,51,51);font-weight:700;font-family:Menlo,=
Monaco,&#39;Courier New&#39;,monospace;line-height:22.3999996185303px;white=
-space:pre-wrap"><span style=3D"color:#008">int</span></span><span style=3D=
"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospa=
ce;font-size:12px;line-height:22.3999996185303px;white-space:pre-wrap;backg=
round-color:rgb(248,248,248)"><span style=3D"color:#000"><br></span></span>=
<span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier Ne=
w&#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-space:=
pre-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#660">}</s=
pan><span style=3D"color:#000"><br></span></span><span style=3D"font-size:1=
2px;vertical-align:baseline;outline:0px;color:rgb(51,51,51);font-weight:700=
;font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-height:22.39=
99996185303px;white-space:pre-wrap"><span style=3D"color:#000">type</span><=
/span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Cour=
ier New&#39;,monospace;font-size:12px;line-height:22.3999996185303px;white-=
space:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"color:#000=
"> </span><span style=3D"color:#606">BigBox</span><span style=3D"color:#000=
"> </span></span><span style=3D"font-size:12px;vertical-align:baseline;outl=
ine:0px;color:rgb(51,51,51);font-weight:700;font-family:Menlo,Monaco,&#39;C=
ourier New&#39;,monospace;line-height:22.3999996185303px;white-space:pre-wr=
ap"><span style=3D"color:#008">struct</span></span><span style=3D"color:rgb=
(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;font-si=
ze:12px;line-height:22.3999996185303px;white-space:pre-wrap;background-colo=
r:rgb(248,248,248)"><span style=3D"color:#000"> </span><span style=3D"color=
:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 <=
/span></span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#=
39;Courier New&#39;,monospace;font-size:12px;line-height:22.3999996185303px=
;white-space:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"col=
or:#606">Timestamp</span><span style=3D"color:#000"> time</span><span style=
=3D"color:#660">.</span><span style=3D"color:#606">Time</span></span><span =
style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&#39;Courier New&#39;=
,monospace;font-size:12px;line-height:22.3999996185303px;white-space:pre-wr=
ap;background-color:rgb(248,248,248)"><span style=3D"color:#000"><br>=C2=A0=
 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#606">SmallBox</span><spa=
n style=3D"color:#000"> =C2=A0</span><span style=3D"color:#800">// &lt;&lt;=
&lt; embedding</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 </span><span style=3D"color:#606">Name</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#660">[]</span></span><span style=3D"font-=
size:12px;vertical-align:baseline;outline:0px;color:rgb(51,51,51);font-weig=
ht:700;font-family:Menlo,Monaco,&#39;Courier New&#39;,monospace;line-height=
:22.3999996185303px;white-space:pre-wrap"><span style=3D"color:#008">string=
</span></span><span style=3D"color:rgb(51,51,51);font-family:Menlo,Monaco,&=
#39;Courier New&#39;,monospace;font-size:12px;line-height:22.3999996185303p=
x;white-space:pre-wrap;background-color:rgb(248,248,248)"><span style=3D"co=
lor:#000"><br></span></span><span style=3D"color:rgb(51,51,51);font-family:=
Menlo,Monaco,&#39;Courier New&#39;,monospace;font-size:12px;line-height:22.=
3999996185303px;white-space:pre-wrap;background-color:rgb(248,248,248)"><sp=
an style=3D"color:#660">}</span></span><span style=3D"color:#000"><br></spa=
n></div></code></div><br>This is very simple and low-level extension of the=
 concept of inheritance;=C2=A0the programmer explicitly specifies the locat=
ion of the base object in the successor.=C2=A0It is strange that this simpl=
e and obvious opportunity not appeared in the C language.</div></div><div><=
br></div><div>I propose enhanced (compared with Go) feature of such embeddi=
ng.=C2=A0We can use the existing &quot;inline&quot; keyword (or some other =
keyword, eg. &quot;embed&quot;) to indicate the embedded fields.<br></div><=
div><br></div><div><div style=3D"border:1px solid rgb(187,187,187);word-wra=
p:break-word;background-color:rgb(250,250,250)"><code><div><font color=3D"#=
660066"><span style=3D"color:#008">struct</span><span style=3D"color:#000">=
 </span><span style=3D"color:#606">SmallBox</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br=
>=C2=A0 </span><span style=3D"color:#008">int</span><span style=3D"color:#0=
00"> a</span><span style=3D"color:#660">,</span><span style=3D"color:#000">=
 b</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> c</=
span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br></sp=
an><span style=3D"color:#660">};</span><span style=3D"color:#000"><br><br><=
/span><span style=3D"color:#008">struct</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#606">BigBox</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=
=A0time_t </span><span style=3D"color:#606">Timestamp</span><span style=3D"=
color:#660">;</span><span style=3D"color:#000"> <br>=C2=A0</span><span styl=
e=3D"color:#008">inline</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#606">SmallBox</span><span style=3D"color:#000"> inlinedBox</spa=
n><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=A0s=
td</span><span style=3D"color:#660">::</span><span style=3D"color:#008">str=
ing</span><span style=3D"color:#000"> </span><span style=3D"color:#606">Nam=
e</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><=
/span><span style=3D"color:#660">};</span><span style=3D"color:#000"><br></=
span></font></div></code></div><br>As a result, we can access to the fields=
 of=C2=A0SmallBox=C2=A0both directly and through an intermediate name &quot=
;inlinedBox&quot;:<br></div><div><br></div><div><div style=3D"border:1px so=
lid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)=
"><code><div><font color=3D"#660066"><span style=3D"color:#606">BigBox</spa=
n><span style=3D"color:#000"> box</span><span style=3D"color:#660">;</span>=
<span style=3D"color:#000"><br>box</span><span style=3D"color:#660">.</span=
><span style=3D"color:#000">a </span><span style=3D"color:#660">=3D</span><=
span style=3D"color:#000"> </span><span style=3D"color:#066">10</span><span=
 style=3D"color:#660">;</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#800">//directly, </span></font><font color=3D"#880000"><span st=
yle=3D"color:#800">like inheritance</span><span style=3D"color:#000"><br>bo=
x</span><span style=3D"color:#660">.</span><span style=3D"color:#000">inlin=
edBox</span><span style=3D"color:#660">.</span><span style=3D"color:#000">b=
 </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">10</span><span style=3D"color:#660">;</span=
><span style=3D"color:#000"> </span><span style=3D"color:#800">// </span></=
font><span style=3D"font-family:Arial,Helvetica,sans-serif;background-color=
:rgb(255,255,255)"><span style=3D"color:#800">using </span><span style=3D"c=
olor:#800">an intermediate name, </span></span><span style=3D"color:rgb(136=
,0,0);font-family:Arial,Helvetica,sans-serif"><span style=3D"color:#800">li=
ke aggregation</span></span></div></code></div><br><br></div></div></blockq=
uote><div><br>... what&#39;s wrong with inheritance? I know people tend to =
believe that using inheritance for something like this is wrong, but these =
cases are <i>exactly</i> why C++ has robust support for multiple inheritanc=
e, unlike most languages.<br></div></div></blockquote><div><br></div><div s=
tyle=3D"font-family:arial,sans-serif;font-size:small">I think it&#39;s for =
object layout. Using inheritance would force you to layout `SmallBox` befor=
e `Timestamp` in the example (unless you make `Timestamp` another base).</d=
iv><div style=3D"font-family:arial,sans-serif;font-size:small"><br></div><d=
iv style=3D"font-family:arial,sans-serif;font-size:small">I&#39;m not famil=
iar with Go, but if this is the OP&#39;s intent, I&#39;d suggest taking a s=
tep further to make the feature help data packing, e.g.</div><div style=3D"=
font-family:arial,sans-serif;font-size:small"><br></div><div style=3D"font-=
family:arial,sans-serif;font-size:small"><div style=3D"border:1px solid rgb=
(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code=
><div><span style=3D"color:#008">struct</span><span style=3D"color:#000"> A=
<br></span><span style=3D"color:#660">{</span><span style=3D"color:#000"><b=
r>=C2=A0 =C2=A0 uint32_t a1</span><span style=3D"color:#660">;</span><span =
style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">ch=
ar</span><span style=3D"color:#000"> a2</span><span style=3D"color:#660">;<=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#660">};</=
span><span style=3D"color:#000"><br><br></span><span style=3D"color:#008">s=
truct</span><span style=3D"color:#000"> B<br></span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 uint32_t b1</span>=
<span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#008">inline</span><span style=3D"color:=
#000"> A</span><span style=3D"color:#660">;</span><span style=3D"color:#000=
"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">char</span><span styl=
e=3D"color:#000"> b2</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#660">};</span></div></code=
></div><div><br></div></div><div><span style=3D"font-family:arial,sans-seri=
f;font-size:small">may allow the size of B to be 12 instead of 16.</span>=
=C2=A0</div></div></blockquote><div><br>So what you want isn&#39;t a type `=
A` at all; it&#39;s a named bundle of declarations that could be inserted i=
nto some other type. After all, `B` doesn&#39;t actually contain the type `=
A`; it contains some declarations that `A` provided. <br><br>It seems to me=
 that this is something that ought to be established at the time that `A` i=
s defined. Along with rules about what kinds of things you&#39;re allowed a=
nd forbidden from putting into them (virtual functions, etc).<br><br>Person=
ally, I don&#39;t see the need for such a thing. Or at least, not in the wa=
y you&#39;s talking about.<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/209f4408-b229-4d6d-a568-f0d9d9f9d3fb%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/209f4408-b229-4d6d-a568-f0d9d9f9d3fb=
%40isocpp.org</a>.<br />

------=_Part_6720_469535419.1456947233713--
------=_Part_6719_1061628349.1456947233712--

.