220 24875 <245e65c5-c96d-4366-b616-814606d4ebe9@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Go-like embedding
Date: Wed, 2 Mar 2016 05:46:28 -0800 (PST)
Lines: 215
Approved: news@gmane.org
Message-ID: <245e65c5-c96d-4366-b616-814606d4ebe9@isocpp.org>
References: <e85c46fd-5e5c-4e43-86ae-978da17cda0c@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_6304_1134666666.1456926388582"
X-Trace: ger.gmane.org 1456926397 27885 80.91.229.3 (2 Mar 2016 13:46:37 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 2 Mar 2016 13:46:37 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBNO53O3AKGQECH4JREY@isocpp.org Wed Mar 02 14:46:37 2016
Return-path: <std-proposals+bncBCEKFTV6ZUMBBNO53O3AKGQECH4JREY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f199.google.com ([209.85.214.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBNO53O3AKGQECH4JREY@isocpp.org>)
	id 1ab76q-0005pu-OJ
	for gclcip-std-proposals@m.gmane.org; Wed, 02 Mar 2016 14:46:37 +0100
Original-Received: by mail-ob0-f199.google.com with SMTP id rt7sf45173491obb.0
        for <gclcip-std-proposals@m.gmane.org>; Wed, 02 Mar 2016 05:46:36 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=3n7nQYsL+8TDXm1QjMJUJIkJM5D56jDORtF0KsOuj6U=;
        b=jNZ2hZS2U0EFgOA0A+iCUfsrAGTmegMEX7lFn2GIj8/Ohts+KorCv23dRlmPtUUVV/
         us5LKndFvRZxDS3ytSeGR8WcD3yvi/0L+MwOtv22TpqQE9mKkT2tWA8wmZsM13vNN+kL
         KcXjk7mFRDCo/qbHeiRd5Viq8ufpHLhKZZ2iNxYKxcovISCOZuwegAHUZKKWjzV2G1Cz
         fjJba+wQQk29HNWzCg8MyxdUUITknjMDwNBomnzspbQdxu7MrB2GmQSI2GbaGOahE46A
         8pxIua6G6Ee0MkY7St/oLGMIRRyhetN0oIZtXAL6lQSOvp7C0EVF8hB0ktYSqBNkITiR
         ktgA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=3n7nQYsL+8TDXm1QjMJUJIkJM5D56jDORtF0KsOuj6U=;
        b=BsI3qBho97FvbMfZW67p4UZJN2VUrDBY2/HH7qRnutJPhMRKOh4JCqoE80NlxU9Mt8
         YyvAKPVCt0L86Mu78Vs59GbzYkXh7vL5kwMDX8tYiy+Z9MJmzVB/ij2t+i8xgPKoJ4oo
         Dt0YVPnKbQtL54PuN2BKveFZ3kOB0zJA0XjLpMGS8RqpPqDLKOMLUQ93as+m93h+9x/C
         evCPW52Z//RhbCQMQt6SvHY1fW9aXABmipWbAD+JSPv0EhxRw38BaZnaG1coQtbYic8v
         WylqMarhudMU72UqiqNqsEUYRL3lvGa6snnSauYk5Mt86IYeiuNnDgcfNVNfsnrgRyvV
         vE3A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=3n7nQYsL+8TDXm1QjMJUJIkJM5D56jDORtF0KsOuj6U=;
        b=DnrL76aBOFFGnoKItNElhmBr3JlY4ALaitAjIl0v5DO9SCkZz3uR3zs4SjFQ8LukoQ
         8are7Qiv6gZLZ/qRzoivM7uGdT7XDvBbD2FYBDsXJCxpmaC7gbkOQu8ChlrIZDS2yd2e
         vp16y+S1x21A6ekJPdGDCrq55G4xg6nOkU9XgGze0J9a0Kgk1k8pGVKULpVVVuALVDaY
         K3kpDIT+EjUz7F1anEOcPUxG8fPxbo2M+5ywn5+tTQHUQEdPJV+4YslZa9zQS/VRBIV1
         DkDGw8MBStv5mnF/S4WwQlUvr/Jbsh/Y7x6YC6Tv2cZiJ/VTyJpa+L10klSH9+JyE4cf
         Irfw==
X-Gm-Message-State: AD7BkJIJG51rSOUTOLzomqctpOnZ2aapMmGioM6Zndf6/AnM+V0XokBELb/4BEVcgvMBZg==
X-Received: by 10.50.87.7 with SMTP id t7mr3538840igz.11.1456926390667;
        Wed, 02 Mar 2016 05:46:30 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.47.154 with SMTP id v26ls2190758iov.91.gmail; Wed, 02 Mar
 2016 05:46:29 -0800 (PST)
X-Received: by 10.50.73.234 with SMTP id o10mr121734igv.10.1456926389490;
        Wed, 02 Mar 2016 05:46:29 -0800 (PST)
In-Reply-To: <e85c46fd-5e5c-4e43-86ae-978da17cda0c@isocpp.org>
X-Original-Sender: jmckesson@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:24875
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/24875>

------=_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--

.
