220 23555 <c087a17d-6ab0-40d3-acd7-e7c364edd388@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: Re: n4428 and Tuple-like access interface reflection
Date: Wed, 6 Jan 2016 10:40:56 -0800 (PST)
Lines: 341
Approved: news@gmane.org
Message-ID: <c087a17d-6ab0-40d3-acd7-e7c364edd388@isocpp.org>
References: <56770133.7070701@wanadoo.fr> <5681D877.3010101@wanadoo.fr>
 <43daa6cd-e152-43c1-ab51-0661779d344b@isocpp.org>
 <n5ug1h$fgg$1@ger.gmane.org>
 <CAB+4KH+bBEwFidv=a5wuOLbyBtSTwy0TKB=r_7Mc_8vx_bRrPA@mail.gmail.com>
 <n60u6u$7ov$1@ger.gmane.org> <568942A9.80700@wanadoo.fr>
 <n6e4n4$q68$1@ger.gmane.org> <568B0DA1.3080704@wanadoo.fr>
 <b98e9903-52b2-41b4-ac89-8c3e8df4d9c1@isocpp.org>
 <n6gnfr$57q$1@ger.gmane.org>
 <7d4bd204-e4c3-4f60-8be5-63d8127daf74@isocpp.org>
 <n6grh7$b8q$1@ger.gmane.org>
 <487ea013-6fcb-4d2e-8bc7-8fe96cdbf0a9@isocpp.org>
 <568C3EC7.8070900@wanadoo.fr>
 <a6ad88f3-2309-499a-aeca-834ecb0dfd0d@isocpp.org>
 <568D5959.9000501@wanadoo.fr>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_53_583534280.1452105657053"
X-Trace: ger.gmane.org 1452105663 23710 80.91.229.3 (6 Jan 2016 18:41:03 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 6 Jan 2016 18:41:03 +0000 (UTC)
Cc: mwoehlke.floss@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBOV7WW2AKGQE6KEN2XI@isocpp.org Wed Jan 06 19:41:02 2016
Return-path: <std-proposals+bncBCEKFTV6ZUMBBOV7WW2AKGQE6KEN2XI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oi0-f69.google.com ([209.85.218.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBOV7WW2AKGQE6KEN2XI@isocpp.org>)
	id 1aGt11-0003bu-Ui
	for gclcip-std-proposals@m.gmane.org; Wed, 06 Jan 2016 19:41:00 +0100
Original-Received: by mail-oi0-f69.google.com with SMTP id y66sf943831454oig.0
        for <gclcip-std-proposals@m.gmane.org>; Wed, 06 Jan 2016 10:40:59 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:content-type: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=zYdyUBltKQnAXRAsYN1S6zTUB2/lazxZKY2xBSATwn8=;
        b=px0hpaAL9L9FrWaXTh7Lt7DgzMsSc3aUdcdz0ZYpE23oE4tGScMXnqOKt9uRm08sfm
         EupdjjrzoHrlqk7NT74C1IH71MY8/M7SMeVpi/DgE1yLxH7yrRtr/d/zt7CphdCnnkrG
         Xv7lI1tXAd5kOd7tvbLxvwqBPFIgfpGEE8rDW+h0z/PQ4LbfhDX2QuBAOHnTe+9FKwga
         gpyzaJ5ebc/ON5xFzTPtJOnyHauHznXdvq/Sap2DR6/5KsLQpgPRLpSGZYFTu7NHp6N3
         jeoSZWYiS14Jxt+zBSWfrRTIClqXReEu4rjP1yC31YSqlx1RbidR55OWlC+2zKfwOWnU
         DLeg==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:content-type: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=zYdyUBltKQnAXRAsYN1S6zTUB2/lazxZKY2xBSATwn8=;
        b=Av5VnkqWVexi6ILHxDvm4kQvx7MwPa68uce0V++zMjhZ2EdbsB2b/clSwaShrvQAM6
         VrpFRw424vPL8PpHt/9CcPNkRi2G+eq1T2g2li2kcNgKVlWLVM+HciadmAHbSYXMbmbP
         T5pRoeLmWwgjWDv97jbB/2iN8PNKrvrurSdE14Jx9wy+hE1DCAnGu3fbtSJGQz5GBam4
         gu+Vsl93AONQ/768cOsxeCVhyJtocqpMZvFpSpJVFW1OA3sATZ+sWv6ucOtBt/TLuVC7
         cxgEWMOT0CuSLfAiXKqcv5zgPKobPvqDgDC19YhrGGZ94R/N0D+C7rbZ8owYRT1L6TXw
         FI6A==
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:cc:message-id:in-reply-to
         :references:subject:mime-version:content-type: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=zYdyUBltKQnAXRAsYN1S6zTUB2/lazxZKY2xBSATwn8=;
        b=CU90WHwc4m3quV+24TeE9hi3PBgq1hHqdliMwdcMY30P0N9GWTX8KFYJ/mCeNinovI
         dmQpFYHXM1PfmhA/p40rwYpVSDdN/jVGfBF/HO7R+/MWuY/SiwG0QATqJGmF+dt/yVKO
         ltPmuttQChB3I9ilMKjJ3xhi2/tnMbOK5UT96T6NW21ezc/rYdBZZ0SBx71S3JWAhLKP
         T1q8v/RV6I2v7Azty7UvwTiRZOQ/x2I41J1/+S7LKL4pdTjTUaazsa4b+3dT9ycUABe1
         tm0mqXTOgN1i9erFacOKuUUR1Zreix5e7qu2O8+bVgWwHNhd1PsIe5g0YCckZrtoNjGG
         V4eg==
X-Gm-Message-State: ALoCoQnXVrmh0fYuyaXG8SnLgqmeuJ+oWefLcsJnC9Yz1g5jwJr3OzQoSBt4TaGZecbScfG6stXPNQ8l7zLjKNCGBTdmCv+FLQ==
X-Received: by 10.182.33.74 with SMTP id p10mr89503783obi.34.1452105659165;
        Wed, 06 Jan 2016 10:40:59 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.165.19 with SMTP id o19ls1085868ioe.53.gmail; Wed, 06 Jan
 2016 10:40:57 -0800 (PST)
X-Received: by 10.50.138.138 with SMTP id qq10mr359295igb.10.1452105657905;
        Wed, 06 Jan 2016 10:40:57 -0800 (PST)
In-Reply-To: <568D5959.9000501@wanadoo.fr>
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:23555
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/23555>

------=_Part_53_583534280.1452105657053
Content-Type: multipart/alternative; 
	boundary="----=_Part_54_1247374328.1452105657053"

------=_Part_54_1247374328.1452105657053
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Wednesday, January 6, 2016 at 1:13:48 PM UTC-5, Vicente J. Botet Escriba=
=20
wrote:
>
> Le 06/01/2016 18:49, Nicol Bolas a =C3=A9crit :
>
> On Tuesday, January 5, 2016 at 5:08:09 PM UTC-5, Vicente J. Botet Escriba=
=20
> wrote:=20
>>
>> Le 05/01/2016 19:20, Nicol Bolas a =C3=A9crit :
>>
>> On Tuesday, January 5, 2016 at 11:38:11 AM UTC-5, Matthew Woehlke wrote:=
=20
>>>
>>> On 2016-01-05 11:00, Nicol Bolas wrote:=20
>>> > On 2016-01-04 22:08, Ville Voutilainen wrote:=20
>>> >>> The question is why would you check for an aggregate?=20
>>> >>=20
>>> >> The goal is that get<N> would be implicitly defined for any=20
>>> "aggregate".=20
>>> >> It should *not* be defined however for types that have non-public=20
>>> >> NSDM's. The question is how to achieve this.=20
>>> >>=20
>>> >> I should note that one answer is "compiler magic". If a standard=20
>>> trait=20
>>> >> is going to be a problem, that may be a strong argument to use=20
>>> compiler=20
>>> >> magic rather than a portable library solution.=20
>>> >=20
>>> > Well, reflection of any kind, which this whole idea relies on, is=20
>>> going to=20
>>> > require compiler magic.=20
>>>
>>> True. The question could be better expressed as whether the compiler=20
>>> magic provides get<N> *directly* (as in, there may be no visible=20
>>> declaration of the generic form of such), or whether get<N> is (visibly=
,=20
>>> in the standard library) implemented with the help of traits (which=20
>>> themselves are compiler magic, but have broader applicability).=20
>>>
>>
>> I say let the whole thing be compiler magic. It'd probably be faster to=
=20
>> compile that way if the compiler can just use intrinsics or whatever to=
=20
>> enumerate the members of the struct.
>>
>> Thanks to all for your help. Could we conclude then that the generation=
=20
>> should be done when
>>
>>    - (1) no private or protected non-static data members and
>>    - (2) no base classes=20
>> ?
>>
>> Do you see a better characterization?
>>
>> We can let the answer to whether it is the compiler that generates them =
or if they are generated using some missing type trait or reflection traits=
 as an open question. =20
>>
>>
>>
>> I realized while reading your post that the structured bindings proposal=
=20
> also keys off of being an aggregate when it is not, strictly speaking,=20
> necessary.
>
> That's when I started to think about what these limitations exist.
>
> Aggregate initialization is all about the compiler generating constructio=
n=20
> code on the fly. Looked at from that perspective, the reasoning for the=
=20
> exclusions can be understood as follows:
>
> 1) *Types with constructors*: You're not supposed to be able to=20
> initialize a type that has a user-provided constructor with anything=20
> *except* a call to one of those constructors. That's how they maintain=20
> invariants.
> 2) *Public-only members*: Access classes exist so that only designated=20
> code can access that value. So you can't initialize such values directly;=
=20
> only designated code (ie: user-provided constructors) may do so.
> 3) *Virtual types*: Generating the construction code would require=20
> dealing with filling in virtual stuff. That's more complex code which wou=
ld=20
> best be expressed with a constructor. Also, virtual stuff alters the layo=
ut=20
> of the type.
> 4) *Types with base classes*: The layout of base classes is not=20
> well-defined, which makes the initialization code more complex.
>
> Notice that C++17 will dispense with #4, presumably because, well, what=
=20
> does it matter? Yes, the layout is not defined by the standard, but every=
=20
> class *has* a layout. The compiler knows what that layout is, so the=20
> compiler can figure out how to put each item in the aggregate list in the=
=20
> right place.
>
> When initializing a type, restriction #3 matters, since you have to fill=
=20
> out the appropriate information. But that information is irrelevant when=
=20
> *accessing* NSDMs, either for these auto-tuplizing functions or for=20
> structured binding.
>
> (note: as I think more on this, it may be problematic with virtual=20
> *inheritance*. But virtual functions themselves ought to be fine,=20
> implementation-wise.)
>
> So when doing structured binding or tuplized access, we should only=20
> require restrictions #1 and #2 (and possibly no virtual inheritance).
>
> I missed why you want to maintain #1. This will eliminate std::tuple and=
=20
> std::pair :(
>

They already have tuple-like interfaces. And structured binding will=20
already need an extensibility mechanism for types that don't fit this=20
criteria.

So just apply those to `tuple` and `pair`.
=20

> I wonder about multiple inheritance. if=20
>
>     struct A: A1, A2 {...};
>
> Is everyone comfortable with=20
>
>     get<0>(a) !=3D get<0>(static_cast<A2&>(a)
>

Yes. It matches with aggregate initialization in C++17.
=20

> BTW, what would get<0>(a) be? static_cast<A1&>(a) or=20
> get<0>(static_cast<A1&>(a))?
>

The same thing it is in aggregate initialization in C++17.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-propos=
als/.

------=_Part_54_1247374328.1452105657053
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Wednesday, January 6, 2016 at 1:13:48 PM UTC-5, Vicente J. Botet Escriba=
 wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
 =20
   =20
 =20
  <div bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div>Le 06/01/2016 18:49, Nicol Bolas a
      =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote type=3D"cite">On Tuesday, January 5, 2016 at 5:08:09 PM UTC=
-5,
      Vicente J. Botet Escriba wrote:
      <blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex=
;border-left:1px #ccc solid;padding-left:1ex">
        <div bgcolor=3D"#FFFFFF" text=3D"#000000">
          <div>Le 05/01/2016 19:20, Nicol Bolas a =C3=A9crit=C2=A0:<br>
          </div>
          <blockquote type=3D"cite">On Tuesday, January 5, 2016 at
            11:38:11 AM UTC-5, Matthew Woehlke wrote:
            <blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left=
:0.8ex;border-left:1px #ccc solid;padding-left:1ex">On 2016-01-05 11:00, Ni=
col Bolas
              wrote: <br>
              &gt; On 2016-01-04 22:08, Ville Voutilainen wrote: <br>
              &gt;&gt;&gt; The question is why would you check for an
              aggregate? <br>
              &gt;&gt; <br>
              &gt;&gt; The goal is that get&lt;N&gt; would be implicitly
              defined for any &quot;aggregate&quot;. <br>
              &gt;&gt; It should *not* be defined however for types that
              have non-public <br>
              &gt;&gt; NSDM&#39;s. The question is how to achieve this. <br=
>
              &gt;&gt; <br>
              &gt;&gt; I should note that one answer is &quot;compiler
              magic&quot;. If a standard trait <br>
              &gt;&gt; is going to be a problem, that may be a strong
              argument to use compiler <br>
              &gt;&gt; magic rather than a portable library solution. <br>
              &gt; <br>
              &gt; Well, reflection of any kind, which this whole idea
              relies on, is going to <br>
              &gt; require compiler magic. <br>
              <br>
              True. The question could be better expressed as whether
              the compiler <br>
              magic provides get&lt;N&gt; *directly* (as in, there may
              be no visible <br>
              declaration of the generic form of such), or whether
              get&lt;N&gt; is (visibly, <br>
              in the standard library) implemented with the help of
              traits (which <br>
              themselves are compiler magic, but have broader
              applicability). <br>
            </blockquote>
            <div><br>
              I say let the whole thing be compiler magic. It&#39;d probabl=
y
              be faster to compile that way if the compiler can just use
              intrinsics or whatever to enumerate the members of the
              struct.<br>
            </div>
            <br>
          </blockquote>
          Thanks to all for your help. Could we conclude then that the
          generation should be done when<br>
          <pre>   - (1) no private or protected non-static data members and
   - (2) no base classes=20
?

Do you see a better characterization?

We can let the answer to whether it is the compiler that generates them or =
if they are generated using some missing type trait or reflection traits as=
 an open question. =20


</pre>
        </div>
      </blockquote>
      <div>I realized while reading your post that the structured
        bindings proposal also keys off of being an aggregate when it is
        not, strictly speaking, necessary.<br>
        <br>
        That&#39;s when I started to think about what these limitations
        exist.<br>
        <br>
        Aggregate initialization is all about the compiler generating
        construction code on the fly. Looked at from that perspective,
        the reasoning for the exclusions can be understood as follows:<br>
        <br>
        1) <b>Types with constructors</b>: You&#39;re not supposed to be
        able to initialize a type that has a user-provided constructor
        with anything <i>except</i> a call to one of those
        constructors. That&#39;s how they maintain invariants.<br>
        2) <b>Public-only members</b>: Access classes exist so that
        only designated code can access that value. So you can&#39;t
        initialize such values directly; only designated code (ie:
        user-provided constructors) may do so.<br>
        3) <b>Virtual types</b>: Generating the construction code would
        require dealing with filling in virtual stuff. That&#39;s more
        complex code which would best be expressed with a constructor.
        Also, virtual stuff alters the layout of the type.<br>
        4) <b>Types with base classes</b>: The layout of base classes
        is not well-defined, which makes the initialization code more
        complex.<br>
        <br>
        Notice that C++17 will dispense with #4, presumably because,
        well, what does it matter? Yes, the layout is not defined by the
        standard, but every class <i>has</i> a layout. The compiler
        knows what that layout is, so the compiler can figure out how to
        put each item in the aggregate list in the right place.<br>
        <br>
        When initializing a type, restriction #3 matters, since you have
        to fill out the appropriate information. But that information is
        irrelevant when <i>accessing</i> NSDMs, either for these
        auto-tuplizing functions or for structured binding.<br>
        <br>
        (note: as I think more on this, it may be problematic with
        virtual <i>inheritance</i>. But virtual functions themselves
        ought to be fine, implementation-wise.)<br>
        <br>
        So when doing structured binding or tuplized access, we should
        only require restrictions #1 and #2 (and possibly no virtual
        inheritance).<br>
      </div>
    </blockquote>
    I missed why you want to maintain #1. This will eliminate std::tuple
    and std::pair :(<br></div></blockquote><div><br>They already have tuple=
-like interfaces. And structured binding will already need an extensibility=
 mechanism for types that don&#39;t fit this criteria.<br><br>So just apply=
 those to `tuple` and `pair`.<br>=C2=A0</div><blockquote class=3D"gmail_quo=
te" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;paddi=
ng-left: 1ex;"><div bgcolor=3D"#FFFFFF" text=3D"#000000">
   =20
    I wonder about multiple inheritance. if <br>
    <br>
    =C2=A0=C2=A0=C2=A0 struct A: A1, A2 {...};<br>
    <br>
    Is everyone comfortable with <br>
    <br>
    =C2=A0=C2=A0=C2=A0 get&lt;0&gt;(a) !=3D get&lt;0&gt;(static_cast&lt;A2&=
amp;&gt;(a)<br></div></blockquote><div><br>Yes. It matches with aggregate i=
nitialization in C++17.<br>=C2=A0</div><blockquote class=3D"gmail_quote" st=
yle=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-lef=
t: 1ex;"><div bgcolor=3D"#FFFFFF" text=3D"#000000">
   =20
    BTW, what would get&lt;0&gt;(a) be? static_cast&lt;A1&amp;&gt;(a) or
    get&lt;0&gt;(static_cast&lt;A1&amp;&gt;(a))?<br></div></blockquote><div=
><br>The same thing it is in aggregate initialization in C++17.<br></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />

------=_Part_54_1247374328.1452105657053--
------=_Part_53_583534280.1452105657053--

.
