220 10462 <e2c9537e-13c2-4f41-9fb9-1b19c82999ce@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: douglas.boffey@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Generated initializer_list
Date: Thu, 1 May 2014 02:52:45 -0700 (PDT)
Lines: 172
Approved: news@gmane.org
Message-ID: <e2c9537e-13c2-4f41-9fb9-1b19c82999ce@isocpp.org>
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>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_3726_31111225.1398937965208"
X-Trace: ger.gmane.org 1398937977 31011 80.91.229.3 (1 May 2014 09:52:57 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 1 May 2014 09:52:57 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDSIZVXVVUFBB3VSRCNQKGQESLGJ6WY@isocpp.org Thu May 01 11:52:49 2014
Return-path: <std-proposals+bncBDSIZVXVVUFBB3VSRCNQKGQESLGJ6WY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f200.google.com ([209.85.214.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDSIZVXVVUFBB3VSRCNQKGQESLGJ6WY@isocpp.org>)
	id 1Wfnfb-0002aC-RP
	for gclcip-std-proposals@m.gmane.org; Thu, 01 May 2014 11:52:48 +0200
Original-Received: by mail-ob0-f200.google.com with SMTP id vb8sf15300152obc.11
        for <gclcip-std-proposals@m.gmane.org>; Thu, 01 May 2014 02:52:46 -0700 (PDT)
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
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=daPSCPM88RBhVD4Qg2ctFoEJp7oEEPp/OX9MKLQimoE=;
        b=NGN53ADF5xBCS5EcA7Ronayowkx2EbT8ncJR9n65BVtQisXEMBDWJdCLB8x0Ss4ICc
         nAb9hn/tg1ZwtVsB0VN7aRZWA0ggdAQS/XJQzJm+Grf3gjuHmaAfjuw0wurs+CSlnp6P
         PSQgVIBFTMTP9rfuz4+nv7XEMNrg3rE7bxhczXL0e/FbB2jfbK1pkpaIonrwGysV8xTE
         cjkRdEmZ8OZ/M0lPyYu5QsSjClgF2mi3PFmeLV+vymmrio2UssQzsHYwKV1gKKMw3WY5
         1i2ah3TBQ94geUelXSqsmgMKgeE+HrTpxxVwxnXWIyAJ8SEOsgjxb3tg2u3LBpGBs4L3
         1V/g==
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:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=daPSCPM88RBhVD4Qg2ctFoEJp7oEEPp/OX9MKLQimoE=;
        b=RuakS0RlizCVyqwg17sOl6BHEvuMwjwzurjk2hs0G9JQKMk2uefwohgTMnTxltNFWP
         2iIOG2MQ7qV+dlVEOdjo47JT7J3t+aOy3vAjDamrFn297yZqiyHFoLWGn0eBDsDE+vET
         HrLpdM4EuXPuhqJX0aYetlrDDQxOr/1ULFXT78C9GsXa5dde4z8CNgWDllw5Z/cXOoPr
         Ckc5V9BwB44OTXO1UsB2wj6e7Ccrybr4Ns4b9VlmV2j7esuhfn68s+WwB0W1NW5jLQsh
         WgLxorqEvCXU+1zIkN6Hnkf+fp2vrFAFAjHaZwVW1SdWeAPEb3Os5/TpbUw6+Rtkn0eQ
         AsZw==
X-Gm-Message-State: ALoCoQmdEUijgKLz2sPTrYbm6OtJ86Fgh8C/v4D2Ol5aw05SDW6wgRTExkEGNdLabLySBXc9IxzG
X-Received: by 10.182.75.193 with SMTP id e1mr5151193obw.1.1398937966779;
        Thu, 01 May 2014 02:52:46 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.95.84 with SMTP id h78ls974515qge.54.gmail; Thu, 01 May
 2014 02:52:45 -0700 (PDT)
X-Received: by 10.140.27.244 with SMTP id 107mr1753qgx.18.1398937965899;
        Thu, 01 May 2014 02:52:45 -0700 (PDT)
In-Reply-To: <CAB+4KH+d-r7LjPWJheymdAbvfrtdesudW7q38KLQtAVbjBkiWg@mail.gmail.com>
X-Original-Sender: douglasboffey@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:10462
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/10462>

------=_Part_3726_31111225.1398937965208
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable


On Tuesday, 29 April 2014 13:56:07 UTC+1, Andrew Tomazos wrote:=20
>
> > 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
>
> 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
>
>     constexpr std::array<int, 5> cache_primes()=20
>     {=20
>         std::array<int, 5> A =3D {0};=20
>
>         for (size_t i =3D 0; i < 5; i++)=20
>              A[i] =3D get_nth_primes(i);=20
>
>        return A;=20
>     }=20
>
>     constexpr std:array<int, 5> primes =3D cache_primes();=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
>
> Is that what you mean?=20
>
=20
This goes part way to resolving the issue, but there are still two major=20
problems with that solution:
=20
a) the size of the array might not be known by the user=E2=80=94suppose, fo=
r=20
example, that I wanted to code tables for a LALR(1) parser (without the=20
need for a source code generator like yacc/byacc/bison), it would be=20
unreasonable for the system to expect the programmer to know the array=20
sizes, and
b) this constrains the user to use a std::array=E2=80=A6 what if it were mo=
re=20
appropriate for a different data structure?
=20
After thinking about it, it seems that the best way to resolve such=20
deficiencies would be to add the necessary ctors to std::initializer_list,=
=20
e.g.
=20
template<typename ValueType>
std::initializer_list<ValueType>::initializer_list(size_t members,=20
ValueType (*fn)(size_t));
=20
which would be equivalent to {fn[0], fn[1], =E2=80=A6, fn[members =E2=80=93=
 1]}
=20
template<typename ValueType, typename Data>
std::initializer_list<ValueType>::initializer_list(ValueType=20
(*next_datum)(const Data data), Data (*iterate)(const Data data), bool=20
(*more)(const Data data), const Data &initial_data)
=20
which would be equivalent to {next_datum(initial_data),=20
next_datum(iterate(initial_data)),=20
next_datum(iterate(iterate(initial_data))), =E2=80=A6}, continuing while=20
more(iterate(=E2=80=A6(initial_data)=E2=80=A6).
=20
I cannot see a way of using a ctor to generate the initializer_list from an=
=20
object, since it would need to be generated within the ctor to be mutable.

--=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/.

------=_Part_3726_31111225.1398937965208
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><BR>On Tuesday, 29 April 2014 13:56:07 UTC+1, Andrew Tomaz=
os wrote:=20
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>&gt; I would like to type somethin=
g along the lines of: <BR>&gt; <BR>&gt; constexpr auto primes[5] =3D get_nt=
h_prime; <BR>&gt; <BR>&gt; given a function <BR>&gt; <BR>&gt; constexpr uns=
igned int get_nth_prime(size_t n) <BR>&gt; <BR>&gt; which would be equivale=
nt 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 a=
n <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; cache_=
primes() <BR>&nbsp; &nbsp; { <BR>&nbsp; &nbsp; &nbsp; &nbsp; std::array&lt;=
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>&n=
bsp; &nbsp; } <BR><BR>&nbsp; &nbsp; constexpr std:array&lt;int, 5&gt; prime=
s =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) i=
s stored in the <BR>object file like you want. <BR><BR>Is that what you mea=
n? <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>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>After thinking about it, it seems that the best way to resolve such de=
ficiencies would be to add the necessary ctors to std::initializer_list, e.=
g.</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=3D#9900ff>template&lt;typename ValueType&gt;</FONT></DIV>
<DIV><FONT color=3D#9900ff>std::initializer_list&lt;ValueType&gt;::initiali=
zer_list(size_t members, ValueType (*fn)(size_t));</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>which would be equivalent to {fn[0], fn[1], =E2=80=A6, fn[members =E2=
=80=93 1]}</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=3D#9900ff>template&lt;typename ValueType, typename Data&gt=
;</FONT></DIV>
<DIV><FONT color=3D#9900ff>std::initializer_list&lt;ValueType&gt;::initiali=
zer_list(ValueType (*next_datum)(const Data data), Data (*iterate)(const Da=
ta data), bool (*more)(const Data data), const Data &amp;initial_data)</FON=
T></DIV>
<DIV>&nbsp;</DIV>
<DIV>which would be equivalent to {next_datum(initial_data), next_datum(ite=
rate(initial_data)), next_datum(iterate(iterate(initial_data))), =E2=80=A6}=
, continuing while more(iterate(=E2=80=A6(initial_data)=E2=80=A6).</DIV>
<DIV>&nbsp;</DIV>
<DIV>I cannot see a way of using a ctor to generate the initializer_list fr=
om an object, since it would need to be generated within the ctor to be mut=
able.</DIV></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"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_3726_31111225.1398937965208--

.
