220 11824 <6598852E-AFEC-4637-A912-725D59B8D748@gmail.com> article
Path: news.gmane.org!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: N4115, N3728: std::tuple as metadata
Date: Fri, 11 Jul 2014 08:56:28 +0800
Lines: 178
Approved: news@gmane.org
Message-ID: <6598852E-AFEC-4637-A912-725D59B8D748@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\))
Content-Type: multipart/alternative; boundary="Apple-Mail=_75100711-2170-4B68-85A1-DCA700621036"
X-Trace: ger.gmane.org 1405040207 32413 80.91.229.3 (11 Jul 2014 00:56:47 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 11 Jul 2014 00:56:47 +0000 (UTC)
Cc: stdbill.h@pobox.com,
 mike_spertus@symantec.com
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBRHM7SOQKGQEJ5O63XI@isocpp.org Fri Jul 11 02:56:40 2014
Return-path: <std-proposals+bncBCW25A7E3QCRBRHM7SOQKGQEJ5O63XI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qa0-f71.google.com ([209.85.216.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBRHM7SOQKGQEJ5O63XI@isocpp.org>)
	id 1X5P8h-00036I-1Y
	for gclcip-std-proposals@m.gmane.org; Fri, 11 Jul 2014 02:56:39 +0200
Original-Received: by mail-qa0-f71.google.com with SMTP id m5sf1345313qaj.10
        for <gclcip-std-proposals@m.gmane.org>; Thu, 10 Jul 2014 17:56:38 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:subject:date:message-id:cc:to:mime-version
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=l/fOywai959i22PvAq8TEQvtDBdGgRmdT0OQl8YOYHM=;
        b=FjuU2S54o2V7ml1cMuqmhE7RkivKwqmgY0JyYVRziSItn/AfAaV7Bdw8dXEZIQAv2p
         2I1dtKKTxjIXI00U0KvpXi75l1LTlIbsveKOy3JcOR7wH1zBiTZUVEXv4HZQdrUSsn7Y
         vtWZeE1+1k0hZNdtagsssKgZaHtiqruyz5FL4w0EOxu4mvWJ+2iS1Qb0kqKrsU17LCbS
         rh76SaYP6Greet7vEgR2doTpGihLOWLYCk7NaWGYJWObYy9sCMJjabDw44IIJrLiUNOr
         oWLifzPypRAeCLJdYeR6fXKzjGAzyMsqsZu/WINh35Z/2Cm6XxZE4OVCxmkfclcB5wKG
         esIA==
X-Gm-Message-State: ALoCoQlBDso+w8/5FUaXqme5xfARmpvtgCqoNG2EGtyHxiwy3ujccVgYNYjvElx0D2gYLLZdc4+9
X-Received: by 10.58.47.229 with SMTP id g5mr24299750ven.38.1405040197960;
        Thu, 10 Jul 2014 17:56:37 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.77.36 with SMTP id p4ls88179igw.19.gmail; Thu, 10 Jul 2014
 17:56:36 -0700 (PDT)
X-Received: by 10.50.124.194 with SMTP id mk2mr238021igb.42.1405040196844;
        Thu, 10 Jul 2014 17:56:36 -0700 (PDT)
Original-Received: from mail-ie0-x22b.google.com (mail-ie0-x22b.google.com [2607:f8b0:4001:c03::22b])
        by mx.google.com with ESMTPS id u7si1888316ics.13.2014.07.10.17.56.36
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 10 Jul 2014 17:56:36 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:4001:c03::22b as permitted sender) client-ip=2607:f8b0:4001:c03::22b;
Original-Received: by mail-ie0-f171.google.com with SMTP id at1so330040iec.30
        for <std-proposals@isocpp.org>; Thu, 10 Jul 2014 17:56:36 -0700 (PDT)
X-Received: by 10.42.80.7 with SMTP id t7mr1014160ick.9.1405040196713;
        Thu, 10 Jul 2014 17:56:36 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.54.43])
        by mx.google.com with ESMTPSA id l5sm1008613ige.6.2014.07.10.17.56.34
        for <multiple recipients>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 10 Jul 2014 17:56:36 -0700 (PDT)
X-Mailer: Apple Mail (2.1878.6)
X-Original-Sender: potswa@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of potswa@gmail.com designates 2607:f8b0:4001:c03::22b as permitted
 sender) smtp.mail=potswa@gmail.com;       dkim=pass header.i=@gmail.com;
       dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://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>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:11824
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11824>

--Apple-Mail=_75100711-2170-4B68-85A1-DCA700621036
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1

I notice some proposals N4115 and N3728 (formerly N3416) advocating extensi=
ons for manipulation of parameter packs. I think they are rejecting std::tu=
ple unnecessarily, potentially adding legwork for users.

From N3728:

> Compilation speed is often gating in metaprogramming. In implementating t=
he bases trait proposed in N3729 as a g++4.7 extension, I compared the perf=
ormance of returning a tuple type giving all the base classes of a class wi=
th returning a simple typelist class containing no members and no recursive=
 expansion. The simple typelist class was 60 times faster to compile. A bui=
lt-in parameter list would presumably be even faster than that. Given that =
the recursive member generation in tuple provides no benefit for typelists,=
 tuple-based typelists should probably be avoided for performance reasons a=
lone.

From N4115:

> A class template that just holds a parameter pack:
>=20
>     template <class... T> struct packer { };
>=20
> This is inspired by std::tuple, but it lacks members, so it could serve a=
s an empty base class, and an object of the ultimate type could always be i=
nstantiated (even if the parameter pack contains void or some type that lac=
ks a default constructor).

My experience with using std::tuple has been quite positive. My project doe=
s heavy meta-lifting with what amounts to a first-order predicate unificati=
on engine, and it compiles in seconds. While developing it, my tests with t=
uple versus an empty packer-like alternative showed no difference.

The key is that instantiating tuple is the only part that's slow, but you n=
ever need to instantiate a metadata type. Before a template-id is ODR-used,=
 it only exists as a disembodied name, not resolved to a partial specializa=
tion, and equal in compiler cost to any other template-id of the same compl=
exity, which is just naked argument list (as proposed in N3728) plus a name=
.. I'm not sure what caused the slowdown mentioned in N3728. Perhaps GCC 4.7=
's std::tuple_element instantiated something, but this no longer happens si=
nce 4.8.

The tuple and tuple-like metafunction interface (std::tuple_size, std::tupl=
e_element, etc) are already specified so as to work without necessarily ins=
tantiating their argument. Rather than adding new facilities to the standar=
d, it would be better to reflect common implementation practice in a requir=
ement that they not instantiate.

Few scenarios exist where pure type-list instantiation is useful. If you ad=
d member metafunctions to the type-list class, then you pay for the declara=
tions of members that are not used. If you do not add members, then nothing=
 is really instantiated. There is tag dispatching, but usage like tag< tupl=
e< x, y, z > > is more expressive.

Codebases written on std::tuple and std::tuple_element exist, but nothing i=
s written against any other std::packer class or naked argument list facili=
ty, so there's a compatibility argument. std::tuple is ready to produce run=
time objects when the user does want them, so there's a convenience argumen=
t.

--
For what it's worth, my application does similar things to N4115, but a Boo=
lean tuple-set-contains metafunction never came up. I ended up with only tu=
ple_upto, which slices a tuple from the beginning to just before a given ty=
pe. (If the type is not found, the argument is returned unsliced.) In metap=
rogramming, if you're going to use initial results to drive further process=
ing, it's important to leverage memoization. I think Boolean set arithmetic=
 throws away too much information to make useful primitives under memoizati=
on. Or, perhaps the take-away lesson is that a generic type-list processing=
 library won't be very useful if built piecemeal from small proposals. Perf=
ormance would be easier to preserve if is_contained_in generated memoized i=
ntermediate results for likely subsequent operations.

--=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 http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_75100711-2170-4B68-85A1-DCA700621036
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;">I notice some proposal=
s N4115 and N3728 (formerly N3416) advocating extensions for manipulation o=
f parameter packs. I think they are rejecting <font face=3D"Courier">std::t=
uple</font> unnecessarily, potentially adding legwork for users.<div><br></=
div><div>From N3728:<div><br></div><div></div><blockquote type=3D"cite"><di=
v>Compilation speed is often gating in metaprogramming. In implementating t=
he&nbsp;bases&nbsp;trait proposed in N3729&nbsp;as a g++4.7 extension, I co=
mpared the performance of returning a&nbsp;tuple&nbsp;type giving all the b=
ase classes of a&nbsp;class with returning a simple typelist&nbsp;class con=
taining no members and no recursive expansion. The simple&nbsp;typelist cla=
ss was 60&nbsp;times faster to compile. A built-in parameter list would pre=
sumably be even faster than&nbsp;that. Given that the recursive member gene=
ration in&nbsp;tuple&nbsp;provides no benefit for&nbsp;typelists,&nbsp;tupl=
e-based&nbsp;typelists should probably be avoided for performance reasons&n=
bsp;alone.</div></blockquote><div><br></div><div>From N4115:</div><div><br>=
</div><div></div><blockquote type=3D"cite"><div>A class template that just =
holds a parameter pack:<br><br><div>&nbsp; &nbsp; template &lt;class... T&g=
t; struct packer { };</div><br class=3D"Apple-interchange-newline">This is =
inspired by&nbsp;std::tuple, but it lacks members,&nbsp;so it could serve a=
s an empty base class,&nbsp;and an object of the&nbsp;ultimate type could a=
lways be instantiated&nbsp;(even if the parameter pack contains&nbsp;void&n=
bsp;or some type that lacks a&nbsp;default constructor).</div></blockquote>=
<div><br></div><div>My experience with using <font face=3D"Courier">std::tu=
ple</font> has been quite positive. My project does heavy meta-lifting with=
 what amounts to a first-order predicate unification engine, and it compile=
s in seconds. While developing it, my tests with tuple versus an empty <fon=
t face=3D"Courier">packer</font>-like alternative showed no difference.</di=
v><div><br></div><div>The key is that instantiating&nbsp;<font face=3D"Cour=
ier">tuple</font> is the only part that&rsquo;s slow, but you never need to=
 instantiate a metadata type. Before a template-id is ODR-used, it only exi=
sts as a disembodied name, not resolved to a partial specialization, and eq=
ual in compiler cost to any other template-id of the same complexity, which=
 is just naked argument list (as proposed in&nbsp;N3728) plus a name. I&rsq=
uo;m not sure what caused the slowdown mentioned in N3728. Perhaps GCC 4.7&=
rsquo;s <font face=3D"Courier">std::tuple_element</font> instantiated somet=
hing, but this no longer happens since 4.8.</div><div><br></div></div><div>=
The tuple and tuple-like metafunction interface (<font face=3D"Courier">std=
::tuple_size</font>, <font face=3D"Courier">std::tuple_element</font>, etc)=
 are already specified so as to work without necessarily instantiating thei=
r argument. Rather than adding new facilities to the standard, it would be =
better to reflect common implementation practice in a requirement that they=
 not instantiate.</div><div><br></div><div>Few scenarios exist where pure t=
ype-list instantiation is useful. If you add member metafunctions to the ty=
pe-list class, then you pay for the declarations of members that are not us=
ed. If you do not add members, then nothing is really instantiated. There i=
s tag dispatching, but usage like&nbsp;<font face=3D"Courier">tag&lt; tuple=
&lt; x, y, z &gt; &gt;</font> is more expressive.</div><div><br></div><div>=
Codebases written on <font face=3D"Courier">std::tuple</font>&nbsp;and <fon=
t face=3D"Courier">std::tuple_element</font> exist, but nothing is written =
against any other&nbsp;<font face=3D"Courier">std::packer</font> class or n=
aked argument list facility, so there&rsquo;s a compatibility argument. <fo=
nt face=3D"Courier">std::tuple</font>&nbsp;is ready to produce runtime obje=
cts when the user does want them, so there&rsquo;s a convenience argument.<=
/div><div><br></div><div>&mdash;</div><div>For what it&rsquo;s worth, my ap=
plication does similar things to N4115, but a Boolean tuple-set-contains me=
tafunction never came up. I ended up with only <font face=3D"Courier">tuple=
_upto</font>, which slices a tuple from the beginning to just before a give=
n type. (If the type is not found, the argument is returned unsliced.) In m=
etaprogramming, if you&rsquo;re going to use initial results&nbsp;to drive =
further processing, it&rsquo;s important to leverage memoization. I think B=
oolean set arithmetic throws away too much information to make useful primi=
tives under memoization. Or, perhaps the take-away lesson is that a generic=
 type-list processing library won&rsquo;t be very useful if built piecemeal=
 from small proposals. Performance would be easier to preserve if <font fac=
e=3D"Courier">is_contained_in</font> generated memoized intermediate result=
s for likely subsequent operations.</div><div><br></div></body></html>

<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"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_75100711-2170-4B68-85A1-DCA700621036--

.
