220 10427 <CAB+4KH+d-r7LjPWJheymdAbvfrtdesudW7q38KLQtAVbjBkiWg@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Andrew Tomazos <andrewtomazos@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Generated initializer_list
Date: Tue, 29 Apr 2014 14:56:07 +0200
Lines: 42
Approved: news@gmane.org
Message-ID: <CAB+4KH+d-r7LjPWJheymdAbvfrtdesudW7q38KLQtAVbjBkiWg@mail.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>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: ger.gmane.org 1398776177 26718 80.91.229.3 (29 Apr 2014 12:56:17 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 29 Apr 2014 12:56:17 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBD5KHQXXWYPRB2GC72NAKGQE44EX6QQ@isocpp.org Tue Apr 29 14:56:10 2014
Return-path: <std-proposals+bncBD5KHQXXWYPRB2GC72NAKGQE44EX6QQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wg0-f69.google.com ([74.125.82.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD5KHQXXWYPRB2GC72NAKGQE44EX6QQ@isocpp.org>)
	id 1Wf7Zy-0006sR-4s
	for gclcip-std-proposals@m.gmane.org; Tue, 29 Apr 2014 14:56:10 +0200
Original-Received: by mail-wg0-f69.google.com with SMTP id k14sf99666wgh.4
        for <gclcip-std-proposals@m.gmane.org>; Tue, 29 Apr 2014 05:56:09 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:date
         :message-id:subject:from:to: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=zZPpXmw36ODMz6vyMtLP+1AYNQ9vnS8dTeRzoyq15nc=;
        b=GL8SMw95p3qOKt+QVO+pwNMaNfo5s2TvVVw7AJsPq5/kK9V4lTir2hIlPuLBhHff7E
         H6y1uespmAOPOsgLBet2tTnZZ1vawnLuvu42IhKsp2Rn96v/QNic0gyrXKQ8TcuBmaVZ
         WgqbpxTqKYO8DWaYszHHt1kn1LUyR+hXhft3dfXdpmYJIM/eeieqwOUIAj4/I4jJlFwm
         n1KiqR5i8YrCr66ZwfwcktIXbNRJ3ZFPcr2ebDrgzchOOq9NpinEd+VDpRamPeyeqNXq
         z5KZLAjVB+eDvODXNWmC+NkhAL5q2uRwjbeyQEHZAjRsyD3SS5Gv5lrUDciM7F3fvMvp
         B75w==
X-Gm-Message-State: ALoCoQnbss/zxpXYASl181ptUP3dGn95E1LjwhJTOII+8tYhfEgSHgUhvJdGVAXaLlJcnuKNXUWJ
X-Received: by 10.152.3.38 with SMTP id 6mr2718146laz.0.1398776169614;
        Tue, 29 Apr 2014 05:56:09 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.91.116 with SMTP id cd20ls62232wib.18.gmail; Tue, 29 Apr
 2014 05:56:08 -0700 (PDT)
X-Received: by 10.194.118.163 with SMTP id kn3mr1053931wjb.77.1398776168312;
        Tue, 29 Apr 2014 05:56:08 -0700 (PDT)
Original-Received: from mail-wg0-x234.google.com (mail-wg0-x234.google.com [2a00:1450:400c:c00::234])
        by mx.google.com with ESMTPS id bo8si8186577wjb.27.2014.04.29.05.56.08
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Tue, 29 Apr 2014 05:56:08 -0700 (PDT)
Received-SPF: pass (google.com: domain of andrewtomazos@gmail.com designates 2a00:1450:400c:c00::234 as permitted sender) client-ip=2a00:1450:400c:c00::234;
Original-Received: by mail-wg0-f52.google.com with SMTP id l18so168580wgh.35
        for <std-proposals@isocpp.org>; Tue, 29 Apr 2014 05:56:08 -0700 (PDT)
X-Received: by 10.194.1.242 with SMTP id 18mr24659959wjp.22.1398776167895;
 Tue, 29 Apr 2014 05:56:07 -0700 (PDT)
Original-Received: by 10.227.203.71 with HTTP; Tue, 29 Apr 2014 05:56:07 -0700 (PDT)
In-Reply-To: <2be92780-bf68-4634-a193-7461f71de3f7@isocpp.org>
X-Original-Sender: andrewtomazos@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of andrewtomazos@gmail.com designates 2a00:1450:400c:c00::234 as
 permitted sender) smtp.mail=andrewtomazos@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:10427
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/10427>

> I would like to type something along the lines of:
>
> constexpr auto primes[5] = get_nth_prime;
>
> given a function
>
> constexpr unsigned int get_nth_prime(size_t n)
>
> which would be equivalent to
>
> constexpr unsigned int primes[] = {2, 3, 5, 7, 11};

Let us ignore prime sieves for the moment, and assume you have an
expensive function get_nth_prime.  You can write the following I
think:

    constexpr std::array<int, 5> cache_primes()
    {
        std::array<int, 5> A = {0};

        for (size_t i = 0; i < 5; i++)
             A[i] = get_nth_primes(i);

       return A;
    }

    constexpr std:array<int, 5> primes = cache_primes();

cache_primes is called during translation (at compile-time), the
primes array is filed out and (assuming odr-used) is stored in the
object file like you want.

Is that what you mean?

-- 

--- 
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.
