220 24878 <2bbe1861-b3b8-49cf-8405-ab840bd7b5fd@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: NeoCode <neoprogramming@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Go-like embedding
Date: Wed, 2 Mar 2016 05:59:34 -0800 (PST)
Lines: 227
Approved: news@gmane.org
Message-ID: <2bbe1861-b3b8-49cf-8405-ab840bd7b5fd@isocpp.org>
References: <e85c46fd-5e5c-4e43-86ae-978da17cda0c@isocpp.org>
 <245e65c5-c96d-4366-b616-814606d4ebe9@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_294_2059805163.1456927175054"
X-Trace: ger.gmane.org 1456927188 8959 80.91.229.3 (2 Mar 2016 13:59:48 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 2 Mar 2016 13:59:48 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBD3J5LU7U4OBBSHD3O3AKGQEZPGELIA@isocpp.org Wed Mar 02 14:59:47 2016
Return-path: <std-proposals+bncBD3J5LU7U4OBBSHD3O3AKGQEZPGELIA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oi0-f71.google.com ([209.85.218.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD3J5LU7U4OBBSHD3O3AKGQEZPGELIA@isocpp.org>)
	id 1ab7JW-0005LT-Jq
	for gclcip-std-proposals@m.gmane.org; Wed, 02 Mar 2016 14:59:42 +0100
Original-Received: by mail-oi0-f71.google.com with SMTP id r187sf82355968oih.3
        for <gclcip-std-proposals@m.gmane.org>; Wed, 02 Mar 2016 05:59:42 -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=2ZFAQcil2ooFwpkTMfcn1TBFLnfVWKB00/GEU5X0xJE=;
        b=XG35hA+OUjs7F41HFhHW8w06U/RDshnbMc+4Mw0sVz+2P41XadzOvlouwRrmVPagrR
         4/n+hDGYksgW4xDN0cmpqkh7XRMR7bFJngzvA/0iNlQqMnyuitOemjNWQs8yZwDaG6vR
         k+1BeIiMnijknPinesPv6FfyuuFE3lMmq+BBGJERftiigzskL225e7htwG4qd9H6206E
         DlBAUAr/UO23IowNPAjb+J5yiGPN2iffF7gwukkL6q1dfPvRtxcxVlk9TmOPqmPj8xc5
         7Rgc4ncZ8YpgptyR7BaxqUIJx+FTWXKJQWX73qkBB/qRNCZm8E4Qzug6OB8pAiHIupS2
         T31A==
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=2ZFAQcil2ooFwpkTMfcn1TBFLnfVWKB00/GEU5X0xJE=;
        b=HNVaf7Tq4ZlE577KeHyrdfEqR9PkNn0A1CyXcXI4tpKzLNQ6OSTthw//dlGGTw6O9L
         8eETAciCM8m86cMznyyhe9SYCkhh6uxSrXm+Xoiv1qKUH0/lWPTRazJKXvzlORTvBttf
         aAicxHKQI17jeFqEz/5lXEZwTZU7vByKuZIQpCX6jnS7ZOR37NpGUR/hIywzwYTL5A0a
         uUT9TZ1XLTBr9XwXnx402oEbOemwaFXLHgyx2ayikTbb6ijasJwDV39HV1hcpaoHxX9E
         8YL2RxDxhvw16JiA07+Ja6x/9Wiwb1jQ82RZO/48AmMky5G1I29NBsfXkoXmScl8A46H
         9Lew==
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=2ZFAQcil2ooFwpkTMfcn1TBFLnfVWKB00/GEU5X0xJE=;
        b=TECwJY6IVrgBXXir96O2L7ev6E8lqiISrSLBGBuK8aqwYKYV6W/jcIx0gNtZX60maB
         cvjUYtKs6suXAw0fttcbpbB0lYtCJfM0ME4m+M9rXjMvH3ESjxwT+o+RtHea4oiTnww4
         ky254wYvLPJACCDAqqnxrZ2M+F1nqxTZJPrQ67kf/oLMJsspSSgebGUo7KsFX6+O54fz
         khe3oQFJL24mW6HRz3+QEzflvv9LUNjYG7ujtdGltZ+MlbRsWD+3O44tavrZJv1P5ZmZ
         uTD+fmOVqGT9rtoJRiW9oDUSsIHGLXS9kKORcooqWDTDfQAYrsQ+oD2qLal9SxHUSu8v
         ospg==
X-Gm-Message-State: AD7BkJIaphtOj/KNh0KQIccd+Q/9QESAhazxcfNHI5PfjbH7/4oGncRP2qYNiB7BlIAksg==
X-Received: by 10.182.148.227 with SMTP id tv3mr20751104obb.30.1456927176724;
        Wed, 02 Mar 2016 05:59:36 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.16.208 with SMTP id 77ls2147115ioq.71.gmail; Wed, 02 Mar
 2016 05:59:35 -0800 (PST)
X-Received: by 10.50.111.100 with SMTP id ih4mr947igb.3.1456927175816;
        Wed, 02 Mar 2016 05:59:35 -0800 (PST)
In-Reply-To: <245e65c5-c96d-4366-b616-814606d4ebe9@isocpp.org>
X-Original-Sender: NeoProgramming@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:24878
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/24878>

------=_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--

.
