220 26218 <9c9cb032-a950-476b-823c-28643ef305d8@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Sergey Vidyuk <sir.vestnik@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: statement folding on variadic templates
 parameters pack
Date: Wed, 8 Jun 2016 11:03:32 -0700 (PDT)
Lines: 167
Approved: news@gmane.org
Message-ID: <9c9cb032-a950-476b-823c-28643ef305d8@isocpp.org>
References: <1e3daa7c-e10a-4589-8118-26f47bc1a0df@isocpp.org>
 <0aa49f06-08b0-433a-a897-720140eb7097@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1710_1167150558.1465409012569"
X-Trace: ger.gmane.org 1465409315 12942 80.91.229.3 (8 Jun 2016 18:08:35 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 8 Jun 2016 18:08:35 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCB6HO5JRMARB5V34G5AKGQEXHARZ3I@isocpp.org Wed Jun 08 20:08:30 2016
Return-path: <std-proposals+bncBCB6HO5JRMARB5V34G5AKGQEXHARZ3I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f198.google.com ([209.85.161.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCB6HO5JRMARB5V34G5AKGQEXHARZ3I@isocpp.org>)
	id 1bAhpI-0000DL-0r
	for gclcip-std-proposals@m.gmane.org; Wed, 08 Jun 2016 20:03:36 +0200
Original-Received: by mail-yw0-f198.google.com with SMTP id n63sf36709506ywf.3
        for <gclcip-std-proposals@m.gmane.org>; Wed, 08 Jun 2016 11:03:35 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=mRCi1Dx60cnpasOnpmS2kasLJGMlpKAyHz+0XEXkKPw=;
        b=ZFs6L3b/0cDFm5UT684pjeGdMmTLkYZ7+aMcFVXhbocOgw/gMoUd9QrYWAQNLTnx3l
         lDyP+VtSQLwM2KBxphIivYJvJQzyEulT1R9GAqGYyq6/QEJ5CfklIE8CwTgomvN+iEHH
         4PpTaOUdC13UZpi0oE1ZD6IdEbwRs7FYNmnJyCroIzzz2cRDf9qFfBChBQRgaLTbne8p
         RV/SJHtXDpC7ABvRZJCQHzs4BFZVXp24QM8iibB16vdOB/dO+fA5YS+1YRRZzxpXFpq3
         8kMCiMDAzJAAt7gaoPFXe1EIzgCvx1Ec+BKPoAuWDGYq5mioHGvPQwRN4H4T4t/hACVi
         +ejw==
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
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=mRCi1Dx60cnpasOnpmS2kasLJGMlpKAyHz+0XEXkKPw=;
        b=RF00fTE9vl8pFk7IssLvUDlS5ZVYMRrLeAs2FfXmKN/LUJdv2LmZkG9eCcnjWuEJV0
         FCoK/F3TD8kku8Tk0+uf/o1Eo+jjY2h7dIHadTaUyJHYueKOHyV5YCuizSzMfep6ABLO
         Hy1KYd6OR8VfI1y8FxVQGc1jswdSuxo0zqY9EeEFf1BvRp7njyfUQfmDfFudTwRLkd1n
         GLK6nLdiKuYBm/sKcMp54pdXjgqUYSZM6PvMRIQqiheIUbpBuib94BAzYQGyMVAm+CJx
         96lEUGqtQYtqYuLU6EI8uJe0RSTxGQBkdiQHFHyyS/tPq7q64/E5OiS4rRCNzBZlg/2h
         7CLg==
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:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=mRCi1Dx60cnpasOnpmS2kasLJGMlpKAyHz+0XEXkKPw=;
        b=V+SqMSjDpoufks80N97lqfKfny+XSccxMoMY5qVvDJiz81c+cO9/RY1VkXKDPIZAza
         9QBb3T7l2cuh3aDm7U41jAorRXoueFRR1yqNnZDxG447ks5JpHi+KtUc+nF4os8tqa+k
         +mLpfzlLqnaQrijgfDJ8Mcc2UN7livKGkb8YLtfHASkpGRMb4vaqJlsohhAK45B6E1ck
         74w1SXJf8UvQoCVN0cg6+SZNr2mpJ/WMnpn/jIjjOcJm1GVQ0zHbgLjF7j5g19AGifs6
         Zvf1tZSg/rs60waIi5rvM49gYTVBD27OVeTfzX5gfV1Fg9SKR1OAG9oGi7WvuetlWkEM
         0PGA==
X-Gm-Message-State: ALyK8tJj3HmupSj93vqbcNPsj3uXhTSXTfyJl/XyCnv5SWbbV3yl9hXsqQzEwkHREXM02Q==
X-Received: by 10.140.154.68 with SMTP id a65mr21639739qha.29.1465409014904;
        Wed, 08 Jun 2016 11:03:34 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.46.9 with SMTP id i9ls1451507ita.5.canary; Wed, 08 Jun 2016
 11:03:33 -0700 (PDT)
X-Received: by 10.36.81.79 with SMTP id s76mr371818ita.9.1465409013729;
        Wed, 08 Jun 2016 11:03:33 -0700 (PDT)
In-Reply-To: <0aa49f06-08b0-433a-a897-720140eb7097@isocpp.org>
X-Original-Sender: sir.vestnik@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:26218
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/26218>

------=_Part_1710_1167150558.1465409012569
Content-Type: multipart/alternative; 
	boundary="----=_Part_1711_1224358494.1465409012569"

------=_Part_1711_1224358494.1465409012569
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Foreach from the presentation you've posted allows to repeat overloaded=20
function or functor with multiple operator() for each argument from a pack=
=20
by abusing coma operator. In C++17 it's even simplier since you don't need=
=20
intermediate garbage initializer_list. You can perform expression folding=
=20
directly and it terribly great (tried it with gcc 6.1).

This kind of folding is the simpliest one. I use it a lot but always feel=
=20
myself sad using such kind of haks. In the example I've shown "if (cond)=20
return foo(arg_from_pack);" statement is folded which can't be done by=20
abusing coma opertor and requires recursive templates. One more thing on=20
the syntax i propose: It allows to solve those kind of tasks without hacks=
=20
or boilerplate code. It uses simple to write and understand construction=20
(simple for human and for compiler).

Sergey Vidyuk

=D1=81=D1=80=D0=B5=D0=B4=D0=B0, 8 =D0=B8=D1=8E=D0=BD=D1=8F 2016 =D0=B3., 21=
:11:21 UTC+6 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=
=D0=BB=D1=8C Greg Marr =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:
>
> On Wednesday, June 8, 2016 at 10:14:50 AM UTC-4, Sergey Vidyuk wrote:
>>
>> Expression folding on a variadic template parameters pack are great and=
=20
>> allows to write internal function stuff inside a function instead of=20
>> writing some recursive template code which is required to be moved outsi=
de=20
>> of the function. But when one want to repeat some statement for every=20
>> element of a parameter pack recursive templates or abusing of coma opera=
tor=20
>> folding are stil the only options. After facing this issue several times=
 I=20
>> start to realize that it would be great to have the following extension =
to=20
>> the C++11 range-for syntax:
>>
>
> Have you seen Sean Parent's for_each_argument?
>
> template <class F, class... Args>
> void for_each_argument(F f, Args&&... args) {
>  [](...){}((f(std::forward<Args>(args)), 0)...);
> }
>
>
>
> There was even a CppCon 2015 talk about it=20
>
> https://www.youtube.com/watch?v=3D2l83JlqkzBk
>
>

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/9c9cb032-a950-476b-823c-28643ef305d8%40isocpp.or=
g.

------=_Part_1711_1224358494.1465409012569
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Foreach from the presentation you&#39;ve posted allows to =
repeat overloaded function or functor with multiple operator() for each arg=
ument from a pack by abusing coma operator. In C++17 it&#39;s even simplier=
 since you don&#39;t need intermediate garbage initializer_list. You can pe=
rform expression folding directly and it terribly great (tried it with gcc =
6.1).<br><br>This kind of folding is the simpliest one. I use it a lot but =
always feel myself sad using such kind of haks. In the example I&#39;ve sho=
wn &quot;if (cond) return foo(arg_from_pack);&quot; statement is folded whi=
ch can&#39;t be done by abusing coma opertor and requires recursive templat=
es. One more thing on the syntax i propose: It allows to solve those kind o=
f tasks without hacks or boilerplate code. It uses simple to write and unde=
rstand construction (simple for human and for compiler).<br><br>Sergey Vidy=
uk<br><br>=D1=81=D1=80=D0=B5=D0=B4=D0=B0, 8 =D0=B8=D1=8E=D0=BD=D1=8F 2016 =
=D0=B3., 21:11:21 UTC+6 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=
=82=D0=B5=D0=BB=D1=8C Greg Marr =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB:=
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Wednesday,=
 June 8, 2016 at 10:14:50 AM UTC-4, Sergey Vidyuk wrote:<blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr">Expression folding on a variadic te=
mplate parameters pack are great and allows to write internal function stuf=
f inside a function instead of writing some recursive template code which i=
s required to be moved outside of the function. But when one want to repeat=
 some statement for every element of a parameter pack recursive templates o=
r abusing of coma operator folding are stil the only options. After facing =
this issue several times I start to realize that it would be great to have =
the following extension to the C++11 range-for syntax:<br></div></blockquot=
e><div><br></div><div>Have you seen Sean Parent&#39;s for_each_argument?</d=
iv><div><br></div><div style=3D"border:1px solid rgb(187,187,187);word-wrap=
:break-word;background-color:rgb(250,250,250)"><code><div><span style=3D"co=
lor:#008">template</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">&lt;</span><span style=3D"color:#008">class</span><span style=
=3D"color:#000"> F</span><span style=3D"color:#660">,</span><span style=3D"=
color:#000"> </span><span style=3D"color:#008">class</span><span style=3D"c=
olor:#660">...</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#606">Args</span><span style=3D"color:#660">&gt;</span><span style=3D"col=
or:#000"><br></span><span style=3D"color:#008">void</span><span style=3D"co=
lor:#000"> for_each_argument</span><span style=3D"color:#660">(</span><span=
 style=3D"color:#000">F f</span><span style=3D"color:#660">,</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#606">Args</span><span styl=
e=3D"color:#660">&amp;&amp;...</span><span style=3D"color:#000"> args</span=
><span style=3D"color:#660">)</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0</span>=
<span style=3D"color:#660">[](...){}((</span><span style=3D"color:#000">f</=
span><span style=3D"color:#660">(</span><span style=3D"color:#000">std</spa=
n><span style=3D"color:#660">::</span><span style=3D"color:#000">forward</s=
pan><span style=3D"color:#660">&lt;</span><span style=3D"color:#606">Arg<wb=
r>s</span><span style=3D"color:#660">&gt;(</span><span style=3D"color:#000"=
>args</span><span style=3D"color:#660">)),</span><span style=3D"color:#000"=
> </span><span style=3D"color:#066">0</span><span style=3D"color:#660">)...=
);</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">}=
</span><span style=3D"color:#000"><br><br></span></div></code></div><div><b=
r><font color=3D"#595959" face=3D"Consolas, Courier New, Lucida Console, mo=
nospace"><span style=3D"font-size:12px;white-space:pre"><br></span></font><=
/div><div><font color=3D"#595959" face=3D"arial, sans-serif"><span style=3D=
"font-size:12px;white-space:pre">There was even a CppCon 2015 talk about it=
 </span></font></div><div><font color=3D"#595959" face=3D"arial, sans-serif=
"><span style=3D"font-size:12px;white-space:pre"><br></span></font></div><d=
iv><font color=3D"#595959" face=3D"arial, sans-serif"><span style=3D"font-s=
ize:12px;white-space:pre"><a href=3D"https://www.youtube.com/watch?v=3D2l83=
JlqkzBk" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39=
;https://www.youtube.com/watch?v\x3d2l83JlqkzBk&#39;;return true;" onclick=
=3D"this.href=3D&#39;https://www.youtube.com/watch?v\x3d2l83JlqkzBk&#39;;re=
turn true;">https://www.youtube.com/watch?<wbr>v=3D2l83JlqkzBk</a></span><b=
r></font></div><div><font color=3D"#595959" face=3D"arial, sans-serif"><spa=
n style=3D"font-size:12px;white-space:pre"><br></span></font></div></div></=
blockquote></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9c9cb032-a950-476b-823c-28643ef305d8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/9c9cb032-a950-476b-823c-28643ef305d8=
%40isocpp.org</a>.<br />

------=_Part_1711_1224358494.1465409012569--

------=_Part_1710_1167150558.1465409012569--

.
