220 8057 <8c654488-9a6d-4d14-ae94-c854bf9fcf8b@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Mark <turck11@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Subsets of constexpr functions should be considered
 constant expressions (in certain cases)
Date: Fri, 6 Dec 2013 20:31:43 -0800 (PST)
Lines: 173
Approved: news@gmane.org
Message-ID: <8c654488-9a6d-4d14-ae94-c854bf9fcf8b@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_1191_17579079.1386390703795"
X-Trace: ger.gmane.org 1386390702 27893 80.91.229.3 (7 Dec 2013 04:31:42 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 7 Dec 2013 04:31:42 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC65PPNS7IERBMGJRKKQKGQECIXO5XY@isocpp.org Sat Dec 07 05:31:47 2013
Return-path: <std-proposals+bncBC65PPNS7IERBMGJRKKQKGQECIXO5XY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vc0-f200.google.com ([209.85.220.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC65PPNS7IERBMGJRKKQKGQECIXO5XY@isocpp.org>)
	id 1Vp9YP-00088Q-Q3
	for gclcip-std-proposals@m.gmane.org; Sat, 07 Dec 2013 05:31:46 +0100
Original-Received: by mail-vc0-f200.google.com with SMTP id hu19sf2956710vcb.11
        for <gclcip-std-proposals@m.gmane.org>; Fri, 06 Dec 2013 20:31:45 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id: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=BXeJcRbdxhzbFX8EX8rzTWp/lPP0sYeh01cTUGuC444=;
        b=sPLZ5LUCbT+efzh8TpDaQemZjD5dVmzJIKFwdPUh/XGlcbSe/sgAiDaFdudNLgFPp4
         lJXEiiEZkGnLZay9TLQUjmmoh5G3GVkb/wOGz5gtfv8qDhAPunvQ3ezLQnSoAr1Ca9Wx
         FV1JxxBy5Mleau8LC1bxNcQ+S6zWECr5SeYV3lsi56FKkfRTlLhdq884g7WdVTU4pQMv
         Ey0j/CdmpBCeUxdW/Veq38VZixv/bziHTFyPSghL7YZgFDR4okQ7jpxXR4iVhOFo4YsW
         7OR1WJ2uUfmCQYgSr0EBVVbBPf/PhmcyOy8GeP4o3UoYdY8qbJ/rL/iZnHLdtM+VymHJ
         Eobg==
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: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=BXeJcRbdxhzbFX8EX8rzTWp/lPP0sYeh01cTUGuC444=;
        b=XCJ2DAbn8isosHwlGM50mrGPkT8wcwxDyWW/o6Y1m9wfEgJ5qknVgh38H/c2QaXNZr
         Gg+TqYKxWqL4HLYfaiK0wT9v0hquFJsOQ9dhoH/wQzz/NfsZvhhVuX85SqdUxMDGnaM1
         TU7mUyBYtY/FdvpxnjllTpwukJvxrJPHEz3B6/TUl+p/20vsPz84c25TVTJvaduYoDKn
         Bcx+tefz3tvR8Likegt8z5BbUm2Tfb5yQ+KcuNCTWrjULKE0BfnAT1Z026UEn4r9PYQz
         mY9Zln9iqp+bfFpL29U8tmoLqms/OFD0ZNcFxYhak1vDUahIR3Oxj1VqWIAYwAOentXA
         zTpg==
X-Gm-Message-State: ALoCoQmGTmYgrzBQEor28qeyhvTNoy55+3LZA68hThpLtVKqyVJ8X+7GRRMryjA42A39QjDo50mk
X-Received: by 10.58.198.116 with SMTP id jb20mr2512594vec.4.1386390704900;
        Fri, 06 Dec 2013 20:31:44 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.222.5 with SMTP id qi5ls443052obc.58.gmail; Fri, 06 Dec
 2013 20:31:44 -0800 (PST)
X-Received: by 10.182.236.232 with SMTP id ux8mr56113obc.12.1386390704283;
        Fri, 06 Dec 2013 20:31:44 -0800 (PST)
X-Original-Sender: turck11@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:8057
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8057>

------=_Part_1191_17579079.1386390703795
Content-Type: text/plain; charset=ISO-8859-1

I've been toying around with the relaxed constexpr rules of C++14 in an SVN 
build of clang. The thought occurred to me that I might be able to use the 
'natural' syntax of a for loop to iterate over the contents in a std::tuple 
at compile-time in a constexpr function. This seems conceptually plausible, 
as I am now allowed to loop over a range at compile-time, but as I found 
out on Stack Overflow<http://stackoverflow.com/questions/20436611/possible-to-instantiate-templates-using-a-for-loop-in-a-c14-constexpr-function>, 
when speaking strict standardese, I cannot instantiate a template (like 
std::get) with my loop variable because the variable is not constexpr, even 
though it is part of a constexpr function.

A simplified example:

template<int N>
constexpr int foo() {
  return N;
}

constexpr int getSum() {
  auto sum = 0;
  for (auto i = 0; i < 10; ++i) {
    sum += foo<i>(); //The interesting part
  }
  return sum;
}

constexpr auto sum = getSum();




I'd like to open discussion as to whether or not it makes sense to allow 
this.


I should also clarify, I understand that constexpr functions can be invoked 
at runtime. I am not talking about that case; there are already cases where 
constexpr functions fail to compile only when used for runtime invocations, 
I would extend that principal to this case. I only propose this relaxation 
for when a constexpr function is evaluated in a compile-time context.

-- 

--- 
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_1191_17579079.1386390703795
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I've been toying around with the relaxed constexpr ru=
les of C++14 in an SVN build of clang. The thought occurred to me that I mi=
ght be able to use the 'natural' syntax of a for loop to iterate over the c=
ontents in a std::tuple at compile-time in a constexpr function. This seems=
 conceptually plausible, as I am now allowed to loop over a range at compil=
e-time, but as I found out on<a href=3D"http://stackoverflow.com/questions/=
20436611/possible-to-instantiate-templates-using-a-for-loop-in-a-c14-conste=
xpr-function"> Stack Overflow</a>, when speaking strict standardese, I cann=
ot instantiate a template (like std::get) with my loop variable because the=
 variable is not constexpr, even though it is part of a constexpr function.=
<br></div><div><br></div><div><div>A simplified example:</div><div><div cla=
ss=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border: 1=
px solid rgb(187, 187, 187); word-wrap: break-word;"><code class=3D"prettyp=
rint"><div class=3D"subprettyprint"><pre class=3D"lang-c prettyprint pretty=
printed" style=3D"margin-bottom: 10px; padding: 5px; font-size: 14px; backg=
round-color: rgb(238, 238, 238); font-family: Consolas, Menlo, Monaco, 'Luc=
ida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans M=
ono', 'Courier New', monospace, serif; overflow: auto; width: auto; max-hei=
ght: 600px; word-wrap: normal; color: rgb(0, 0, 0); line-height: 18px;"><co=
de style=3D"font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Libera=
tion Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', =
monospace, serif;"><span style=3D"color: #008;" class=3D"styled-by-prettify=
">template</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> N</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">constexpr</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> foo</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nb=
sp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">return=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> N</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">constexpr</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> getSum</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> sum </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
66;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br>&nbsp; </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">for</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> i </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> i </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">10=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">++</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">i</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>&nbsp; &nbsp; sum </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">+=3D</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> foo</span><span style=3D"color: #080;" class=3D"styled-by-prettif=
y">&lt;i&gt;</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">();</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #800;" class=3D"styled-by-prettify">//The interest=
ing part</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r>&nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp;=
 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> sum</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">constexpr</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> sum </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> getSum</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
);</span></code></pre></div></code></div><br><br><div><br></div><div>I'd li=
ke to open discussion as to whether or not it makes sense to allow this.</d=
iv></div></div><div><br></div><div><br></div><div>I should also clarify, I =
understand that constexpr functions can be invoked at runtime. I am not tal=
king about that case; there are already cases where constexpr functions fai=
l to compile only when used for runtime invocations, I would extend that pr=
incipal to this case. I only propose this relaxation for when a constexpr f=
unction is evaluated in a compile-time context.</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_1191_17579079.1386390703795--

.
