220 6938 <b0d9811a-a6d9-46b2-8a65-2ca54a365b3c@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Andrew Tomazos <andrewtomazos@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: constexpr-specified loop variable
Date: Thu, 3 Oct 2013 15:56:23 -0700 (PDT)
Lines: 150
Approved: news@gmane.org
Message-ID: <b0d9811a-a6d9-46b2-8a65-2ca54a365b3c@isocpp.org>
References: <8527db17-8c8a-43c5-b159-4e14c879f774@isocpp.org>
 <CAOfiQqkW+PwzfoocFMcMeW=Wsrh_uWzfVUBaDJc4FiE5zFHpGw@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_48_5406402.1380840983781"
X-Trace: ger.gmane.org 1380840982 20092 80.91.229.3 (3 Oct 2013 22:56:22 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 3 Oct 2013 22:56:22 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBD5KHQXXWYPRBGHMW6JAKGQEBDVQ3HI@isocpp.org Fri Oct 04 00:56:27 2013
Return-path: <std-proposals+bncBD5KHQXXWYPRBGHMW6JAKGQEBDVQ3HI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yh0-f70.google.com ([209.85.213.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD5KHQXXWYPRBGHMW6JAKGQEBDVQ3HI@isocpp.org>)
	id 1VRron-0007HC-Nw
	for gclcip-std-proposals@m.gmane.org; Fri, 04 Oct 2013 00:56:26 +0200
Original-Received: by mail-yh0-f70.google.com with SMTP id i72sf6811289yha.5
        for <gclcip-std-proposals@m.gmane.org>; Thu, 03 Oct 2013 15:56:24 -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=BdShtsZnduUQ8L5t+PASXOhPSOoy4IoyMvt/BkUk0vY=;
        b=UWB5sh57xHTIA7d0E5yHKJKK7397iikXn4e3mMYCvDYRkLV604PphoVu8lmmq5wBgV
         YoUgI48RVhiJq3S2Y0KVEFSFtsHGBVXxv6d7SGn1EzWV5PNUFNQKpEVwZD96RQBfBfAx
         RvEru3rP7f5oF0ZVzyK+6X4FLpyMSh+bgeJpzSiuHsKVk6VAq4fbu8J2WnNQDHr3Qj0t
         C4p7XoeubRnl5mDpwOaVbfs1RW9CEiJVtXa5oVDrFd4/AGauDLD5x7cTKMP7xvmnpihM
         l/UttLvqsnOIWnp+Bzu2F9FeGHl14bPhSraA3znnSP+Nm7w5oYI0rjm17sAJhLkZK2ys
         kSBA==
X-Received: by 10.236.13.36 with SMTP id a24mr9389812yha.50.1380840984836;
        Thu, 03 Oct 2013 15:56:24 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.0.12 with SMTP id 12ls1141066qea.25.gmail; Thu, 03 Oct 2013
 15:56:24 -0700 (PDT)
X-Received: by 10.49.133.225 with SMTP id pf1mr454172qeb.6.1380840984255;
        Thu, 03 Oct 2013 15:56:24 -0700 (PDT)
In-Reply-To: <CAOfiQqkW+PwzfoocFMcMeW=Wsrh_uWzfVUBaDJc4FiE5zFHpGw@mail.gmail.com>
X-Original-Sender: andrewtomazos@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:6938
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/6938>

------=_Part_48_5406402.1380840983781
Content-Type: text/plain; charset=ISO-8859-1

On Thursday, October 3, 2013 10:34:12 PM UTC+2, Richard Smith wrote:
>
> It's not true that we can't use 'constexpr' to specify a loop variable.
>

Yes, as per my followup to Daniel I meant that it isn't effectively 
possible because of how range-based for is currently defined.

The semantics are as if the loop is unrolled in the obvious way.
>>
>
> If you want to force loop unrolling, it would seem much more natural to 
> use a pack expansion.
>
 
The purpose isn't to force unrolling, the term "unrolled" is purely for 
specification purposes.  An implementation is free to unroll a normal loop, 
and is free to rollup an "unrolled" loop.  It's purely the logical 
behaviour of the program that is specified.

Using a construct like 'for' would violate peoples' intuitions.  'for' does 
> not usually imply code duplication,
>
 
The behaviour of a program containing:

      for (T x : L)

and the same one instead containing:

    for (constexpr T x : L)

are identical if both well-formed.  So it isn't clear how it is 
unintuitive.  As stated the code duplication is only logical.

a 'constexpr' variable declaration can usually have only a single value
>

In the following:

    template<int x>
    constexpr int g()
    {
        constexpr int y = x*2;

        return y + 5;
    }

    constexpr int z1 = g<3>();
    constexpr int z2 = g<4>();

The `y` constexpr variable declaration has two different values, 6 and 8.

Just like in the following:

    for (constexpr int x : {3,4})
    {
        constexpr int y = x*2;

        /* ... */
    }

We can think of the inner statement of the unrolled for statement as if it 
were the body of a unnamed template function, and the loop variable as a 
non-type template parameter.  The body is instantiated and called once for 
each element of the constexpr array initializer.

-- 

--- 
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/.

------=_Part_48_5406402.1380840983781
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Thursday, October 3, 2013 10:34:12 PM UTC+2, Richard Sm=
ith wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:=
 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><di=
v>It's not true that we can't use 'constexpr' to specify a loop variable.</=
div></div></blockquote><div class=3D"gmail_quote"><br>Yes, as per my follow=
up to Daniel I meant that it isn't effectively possible because of how rang=
e-based for is currently defined.<br><br><blockquote style=3D"margin: 0px 0=
px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;=
" class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0=
 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">The=
 semantics are as if the loop is unrolled in the obvious way.<br>
</div></blockquote><div><br></div><div>If you want to force loop unrolling,=
 it would seem much more natural to use a pack expansion.</div></blockquote=
><div>&nbsp;</div>The purpose isn't to force unrolling, the term "unrolled"=
 is purely for specification purposes.&nbsp; An implementation is free to u=
nroll a normal loop, and is free to rollup an "unrolled" loop.&nbsp; It's p=
urely the logical behaviour of the program that is specified.<br><br><block=
quote style=3D"margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 2=
04, 204); padding-left: 1ex;" class=3D"gmail_quote"><div>Using a construct =
like 'for' would violate peoples' intuitions.&nbsp; 'for'=20
does not usually imply code duplication,</div></blockquote><div>&nbsp;</div=
>The behaviour of a program containing:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; for (T x : L)<br><br>and the same one instead containing:<br><br>&nbsp;&=
nbsp;&nbsp; for (constexpr T x : L)<br><br>are identical if both well-forme=
d.&nbsp; So it isn't clear how it is unintuitive.&nbsp; As stated the code =
duplication is only logical.<br><br><blockquote style=3D"margin: 0px 0px 0p=
x 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" cla=
ss=3D"gmail_quote"><div> a 'constexpr' variable=20
declaration can usually have only a single value</div>
</blockquote><div><br></div>In the following:<br><br><span style=3D"font-fa=
mily: courier new,monospace;">&nbsp;&nbsp;&nbsp; template&lt;int x&gt;</spa=
n><br><span style=3D"font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp=
; constexpr int g()</span><br><span style=3D"font-family: courier new,monos=
pace;">&nbsp;&nbsp;&nbsp; {</span><br><span style=3D"font-family: courier n=
ew,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; constexpr int y =
=3D x*2;</span><br><span style=3D"font-family: courier new,monospace;"></sp=
an><br><span style=3D"font-family: courier new,monospace;">&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp; return y + 5;</span><br><span style=3D"font-fami=
ly: courier new,monospace;">&nbsp;&nbsp;&nbsp; }</span><br><br><span style=
=3D"font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; constexpr int z=
1 =3D g&lt;3&gt;();<br>&nbsp;&nbsp;&nbsp; constexpr int z2 =3D g&lt;4&gt;()=
;<br></span><br>The `y` constexpr variable declaration has two different va=
lues, 6 and 8.<br><br>Just like in the following:<br><br><span style=3D"fon=
t-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; for (constexpr int x :=
 {3,4})<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; constexpr int y =3D x*2;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; /* ... */<br>&nbsp;&nbsp;&nbsp; }<br></span><br>We can think of the inne=
r statement of the unrolled for statement as if it were the body of a unnam=
ed template function, and the loop variable as a non-type template paramete=
r.&nbsp; The body is instantiated and called once for each element of the c=
onstexpr array initializer.<br><br></div></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_48_5406402.1380840983781--

.
