220 10464 <F6AB8001-807E-48B7-B972-57A500BBD2BE@gmail.com> article
Path: news.gmane.org!not-for-mail
From: Nicola Gigante <nicola.gigante@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Generated initializer_list
Date: Thu, 1 May 2014 12:30:06 +0200
Lines: 145
Approved: news@gmane.org
Message-ID: <F6AB8001-807E-48B7-B972-57A500BBD2BE@gmail.com>
References: <357dd72f-c749-4dc5-aa6d-5ac4528aba5a@isocpp.org> <CAB+4KHKqB1NC=HYjrZSm=Brj7-Vh50ovTJjnJYpq-Css+mUssw@mail.gmail.com> <2be92780-bf68-4634-a193-7461f71de3f7@isocpp.org> <CAB+4KH+d-r7LjPWJheymdAbvfrtdesudW7q38KLQtAVbjBkiWg@mail.gmail.com> <e2c9537e-13c2-4f41-9fb9-1b19c82999ce@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (1.0)
Content-Type: multipart/alternative;
	boundary=Apple-Mail-B0131C36-B5B1-4B02-B2EE-F3E730ABE301
Content-Transfer-Encoding: 7bit
X-Trace: ger.gmane.org 1398940219 29988 80.91.229.3 (1 May 2014 10:30:19 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 1 May 2014 10:30:19 +0000 (UTC)
To: "std-proposals@isocpp.org" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDMMZOF5V4KBBM6ERCNQKGQEC4RQ2HI@isocpp.org Thu May 01 12:30:12 2014
Return-path: <std-proposals+bncBDMMZOF5V4KBBM6ERCNQKGQEC4RQ2HI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wi0-f200.google.com ([209.85.212.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDMMZOF5V4KBBM6ERCNQKGQEC4RQ2HI@isocpp.org>)
	id 1WfoFo-0005v3-MK
	for gclcip-std-proposals@m.gmane.org; Thu, 01 May 2014 12:30:12 +0200
Original-Received: by mail-wi0-f200.google.com with SMTP id d1sf185146wiv.7
        for <gclcip-std-proposals@m.gmane.org>; Thu, 01 May 2014 03:30:12 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:subject:references:from:in-reply-to:message-id
         :date: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:content-transfer-encoding;
        bh=bMapMZQ1mHTsfSrD2t7v57mdc3FR+UJhrVr61ATDB2Q=;
        b=YDyTQU6VgZsCsecesWoK/S1XVXYniLyYET7bSCOVIHy0asLlQAYrKXRAIzfmWK0IBK
         2dr0wSyRCJg8R9KGzcjMuh6MPqrxbEth6IMQ83oDLjgNb/US3XZhjUM577xV2CrQjOJ2
         8oHiF2RJJOrxresQ3J/OPTCLmDuSTl8C3MCe8IrN5eTpnEfEHMLudDdffwgyFr3a9C3O
         xSLuR60gls5Y7eajlqnb8eicmAM3k00pH3CAyZxZyH8GxK2z8yyzhWuYAW3cP2Qkwog4
         zujBL7gBuSuV65y5GcYChgypxyHKvJPljLZOva8XfmWeI1LCzhW32j5P/kGkgq2O1WWf
         yBZg==
X-Gm-Message-State: ALoCoQm9TduxC3HALgbGWBvMB9X3IcdKsCGEdSc2Ytg9XPTeD3cE72yHw3y+UN+K7cUg1HtRLcDZ
X-Received: by 10.112.50.50 with SMTP id z18mr979378lbn.7.1398940212197;
        Thu, 01 May 2014 03:30:12 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.10.131 with SMTP id i3ls937962wib.31.canary; Thu, 01 May
 2014 03:30:10 -0700 (PDT)
X-Received: by 10.14.225.132 with SMTP id z4mr9254212eep.92.1398940210778;
        Thu, 01 May 2014 03:30:10 -0700 (PDT)
Original-Received: from mail-ee0-x22e.google.com (mail-ee0-x22e.google.com [2a00:1450:4013:c00::22e])
        by mx.google.com with ESMTPS id s46si33734291eeg.195.2014.05.01.03.30.10
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 01 May 2014 03:30:10 -0700 (PDT)
Received-SPF: pass (google.com: domain of nicola.gigante@gmail.com designates 2a00:1450:4013:c00::22e as permitted sender) client-ip=2a00:1450:4013:c00::22e;
Original-Received: by mail-ee0-f46.google.com with SMTP id t10so2135303eei.19
        for <std-proposals@isocpp.org>; Thu, 01 May 2014 03:30:10 -0700 (PDT)
X-Received: by 10.15.73.134 with SMTP id h6mr9150717eey.3.1398940210598;
        Thu, 01 May 2014 03:30:10 -0700 (PDT)
Original-Received: from [10.211.185.65] ([217.200.202.53])
        by mx.google.com with ESMTPSA id q41sm75264524eez.7.2014.05.01.03.30.09
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 01 May 2014 03:30:09 -0700 (PDT)
X-Mailer: iPhone Mail (11D201)
In-Reply-To: <e2c9537e-13c2-4f41-9fb9-1b19c82999ce@isocpp.org>
X-Original-Sender: nicola.gigante@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of nicola.gigante@gmail.com designates 2a00:1450:4013:c00::22e as
 permitted sender) smtp.mail=nicola.gigante@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: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:10464
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/10464>

--Apple-Mail-B0131C36-B5B1-4B02-B2EE-F3E730ABE301
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Il giorno 01/mag/2014, alle ore 11:52, douglas.boffey@gmail.com ha scritto:
>=20
>=20
>> On Tuesday, 29 April 2014 13:56:07 UTC+1, Andrew Tomazos wrote:
>> > I would like to type something along the lines of:=20
>> >=20
>> > constexpr auto primes[5] =3D get_nth_prime;=20
>> >=20
>> > given a function=20
>> >=20
>> > constexpr unsigned int get_nth_prime(size_t n)=20
>> >=20
>> > which would be equivalent to=20
>> >=20
>> > constexpr unsigned int primes[] =3D {2, 3, 5, 7, 11};=20
>>=20
>> Let us ignore prime sieves for the moment, and assume you have an=20
>> expensive function get_nth_prime.  You can write the following I=20
>> think:=20
>>=20
>>     constexpr std::array<int, 5> cache_primes()=20
>>     {=20
>>         std::array<int, 5> A =3D {0};=20
>>=20
>>         for (size_t i =3D 0; i < 5; i++)=20
>>              A[i] =3D get_nth_primes(i);=20
>>=20
>>        return A;=20
>>     }=20
>>=20
>>     constexpr std:array<int, 5> primes =3D cache_primes();=20
>>=20
>> cache_primes is called during translation (at compile-time), the=20
>> primes array is filed out and (assuming odr-used) is stored in the=20
>> object file like you want.=20
>>=20
>> Is that what you mean?
> =20
> This goes part way to resolving the issue, but there are still two major =
problems with that solution:
> =20
> a) the size of the array might not be known by the user=E2=80=94suppose, =
for example, that I wanted to code tables for a LALR(1) parser (without the=
 need for a source code generator like yacc/byacc/bison), it would be unrea=
sonable for the system to expect the programmer to know the array sizes, an=
d

In this specific case, the size of the table is easily computed ahead of ti=
me, so you can compute the template parameter with another constexpr functi=
on, the user doesn't have to know anything.=20

> b) this constrains the user to use a std::array=E2=80=A6 what if it were =
more appropriate for a different data structure?
> =20

It can be any literal data type, actually. The problem is that you can't al=
locate memory in a constexpr context, so your data structures are limited t=
o something whose size you can compute in advance.

Bye,
Nicola=20

--=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-B0131C36-B5B1-4B02-B2EE-F3E730ABE301
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html><head><meta http-equiv=3D"content-type" content=3D"text/html; charset=
=3Dutf-8"></head><body dir=3D"auto"><div>Il giorno 01/mag/2014, alle ore 11=
:52, <a href=3D"mailto:douglas.boffey@gmail.com">douglas.boffey@gmail.com</=
a> ha scritto:</div><div><br></div><blockquote type=3D"cite"><div><div dir=
=3D"ltr"><br>On Tuesday, 29 April 2014 13:56:07 UTC+1, Andrew Tomazos wrote=
:=20
<blockquote style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3D"gmail_quote">&gt; I would like to type someth=
ing along the lines of: <br>&gt; <br>&gt; constexpr auto primes[5] =3D get_=
nth_prime; <br>&gt; <br>&gt; given a function <br>&gt; <br>&gt; constexpr u=
nsigned int get_nth_prime(size_t n) <br>&gt; <br>&gt; which would be equiva=
lent to <br>&gt; <br>&gt; constexpr unsigned int primes[] =3D {2, 3, 5, 7, =
11}; <br><br>Let us ignore prime sieves for the moment, and assume you have=
 an <br>expensive function get_nth_prime. &nbsp;You can write the following=
 I <br>think: <br><br>&nbsp; &nbsp; constexpr std::array&lt;int, 5&gt; cach=
e_primes() <br>&nbsp; &nbsp; { <br>&nbsp; &nbsp; &nbsp; &nbsp; std::array&l=
t;int, 5&gt; A =3D {0}; <br><br>&nbsp; &nbsp; &nbsp; &nbsp; for (size_t i =
=3D 0; i &lt; 5; i++) <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;A=
[i] =3D get_nth_primes(i); <br><br>&nbsp; &nbsp; &nbsp; &nbsp;return A; <br=
>&nbsp; &nbsp; } <br><br>&nbsp; &nbsp; constexpr std:array&lt;int, 5&gt; pr=
imes =3D cache_primes(); <br><br>cache_primes is called during translation =
(at compile-time), the <br>primes array is filed out and (assuming odr-used=
) is stored in the <br>object file like you want. <br><br>Is that what you =
mean? <br></blockquote>
<div>&nbsp;</div>
<div>This goes part way to resolving the issue, but there are still two maj=
or problems with that solution:</div>
<div>&nbsp;</div>
<div>a) the size of the array might not be known by the user=E2=80=94suppos=
e, for example, that I wanted to code tables for a LALR(1) parser (without =
the need for a source code generator like yacc/byacc/bison), it would be un=
reasonable for the system to expect the programmer to know the array sizes,=
 and</div></div></div></blockquote><div><br></div><div>In this specific cas=
e, the size of the table is easily computed ahead of time, so you can compu=
te the template parameter with another constexpr function, the user doesn't=
 have to know anything.&nbsp;</div><br><blockquote type=3D"cite"><div><div =
dir=3D"ltr">
<div>b) this constrains the user to use a std::array=E2=80=A6 what if it we=
re more appropriate for a different data structure?</div>
<div>&nbsp;</div></div>
</div></blockquote><div><br></div><div>It can be any literal data type, act=
ually. The problem is that you can't allocate memory in a constexpr context=
, so your data structures are limited to something whose size you can compu=
te in advance.</div><div><br></div><div>Bye,</div><div>Nicola&nbsp;</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-B0131C36-B5B1-4B02-B2EE-F3E730ABE301--

.
