220 26132 <6b4ef651-55b3-4b93-a6ac-574b55c7f759@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: schreiber.corentin@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Allowing unnammed loop variable in range-based for loops?
Date: Fri, 3 Jun 2016 03:37:16 -0700 (PDT)
Lines: 153
Approved: news@gmane.org
Message-ID: <6b4ef651-55b3-4b93-a6ac-574b55c7f759@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_204_1560168322.1464950236858"
X-Trace: ger.gmane.org 1464950250 11765 80.91.229.3 (3 Jun 2016 10:37:30 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 3 Jun 2016 10:37:30 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCQLNPVMQILRBXN3YW5AKGQEPDRUW3Q@isocpp.org Fri Jun 03 12:37:26 2016
Return-path: <std-proposals+bncBCQLNPVMQILRBXN3YW5AKGQEPDRUW3Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-it0-f69.google.com ([209.85.214.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCQLNPVMQILRBXN3YW5AKGQEPDRUW3Q@isocpp.org>)
	id 1b8mTf-0005xK-Mh
	for gclcip-std-proposals@m.gmane.org; Fri, 03 Jun 2016 12:37:19 +0200
Original-Received: by mail-it0-f69.google.com with SMTP id i127sf135877580ita.2
        for <gclcip-std-proposals@m.gmane.org>; Fri, 03 Jun 2016 03:37:18 -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: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=PqJPhyHos0SvYjkL/EsiI9JCpWOHjASOiEXX/oABUHE=;
        b=vqxeBFiYrNV3udopOLVr+Sbc3Tc5PQTXxiR76JMUoI6ORRyLIgnx9UUxuVkSfzfRSG
         Vykxvjgm28jZ1qrSDeRDUI+FekDE57Ki8Re+lbXS3ZieiEWi+sD2nRrVojyV68wVzxeL
         EUDBjKNAKfBBeFGT+Vbuvdvxiex4R18v/mvpeghaBKNtOnEODn1i6WSmuqwbY8cCwREn
         4LccV51KFP9FJIzTz/ArDK2XzSJ1s8ul3r3FpC5qs2Pw4IyyQU6IEUpEo4mDmobQJ7Dr
         sUv7ow9Gq0e9/wNhCNGGx3l+Ovhptp9fWkbClL5U3oX32fyIjeqebxASoWo8KDAPjDeA
         bjcg==
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:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=PqJPhyHos0SvYjkL/EsiI9JCpWOHjASOiEXX/oABUHE=;
        b=Jyxg8BoWVMmsyU3jNjxNJiesLOGu+6kWi45gpe2zdY5ohfzwRU8RORSaQ6KaqqOQxp
         eialwRTABMTl3du5vVaqtG63Z3LL+trRGthNc4i6cKW3WrbYnGuBtHTPaXeI1PBhiO/Y
         dmpJ+6CxzJ/0VaanARm5Be/B5uMQBzY21sAAsbRTrD9IKV7P7szSUzHCZAvtOk2R5x5U
         XIBNhMDEKYZJioWCO652kzYteqJrxy9hYXa0UhjYRoRTqfNCnsd7so2uUZN38g6jsOZ3
         r1inCaP9xHhgVjoyz5U8MMN39XJzjUI2X5fjSBn/TO/FjjcKBz/rYC7Z1vvO6uJ0+f5s
         eWiw==
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
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=PqJPhyHos0SvYjkL/EsiI9JCpWOHjASOiEXX/oABUHE=;
        b=MwNaslUNkntlGelVuD3cP/B6Vcpvir220ADVZKUcKcU6NKMsAiWqfXGNq34OQJlAWY
         koiKhwYI9/JvGmPG/ZZSkZSRi9eVEo/BNmFim5aLc6WHu+e9ztMjn6KK9vrv0EyH/hGX
         R0QrbA0/9psd1SHKECwR+lit6WsMe94aIMZUXiKG998nCbb8ZUl3DmRz5JvrCIJXvOBi
         XGA7/qg/BOgmoCEdtXAjw0UyZZp/pGZATW91aSGGEYpQSSOutKCtO138SCmZP9O+Bmz8
         JOjaTQDMpBmog6eTALKsJbLauRI3kGtQ0rDhfCgLtxpHMPdI/+gPFUIMVLW86PJwCVH8
         iphw==
X-Gm-Message-State: ALyK8tJatn2slhWEfrBgolmN9XLHAx6G22xzIK0RBxFVTFsiFGxsoH0sa+baHiLjQGpCUw==
X-Received: by 10.36.43.69 with SMTP id h66mr2596183ita.10.1464950238255;
        Fri, 03 Jun 2016 03:37:18 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.150.195 with SMTP id z186ls336800itd.40.gmail; Fri, 03 Jun
 2016 03:37:17 -0700 (PDT)
X-Received: by 10.36.213.134 with SMTP id a128mr77114itg.8.1464950237551;
        Fri, 03 Jun 2016 03:37:17 -0700 (PDT)
X-Original-Sender: schreiber.corentin@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:26132
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/26132>

------=_Part_204_1560168322.1464950236858
Content-Type: multipart/alternative; 
	boundary="----=_Part_205_291784764.1464950236859"

------=_Part_205_291784764.1464950236859
Content-Type: text/plain; charset=UTF-8

I have defined a utility function "range(n)" that generates a input 
sequence of integers from 0 to n-1 such that
for (int i : range(10)) {
    // ...
}

// Is equivalent to

for (int i = 0; i < 10; ++i) {
    // ...
}

I think a similar utility is present in the range TS, although I do not 
know it exact name.

I recently encountered a situation when I needed to perform "n" iterations, 
but without caring about "which" iteration is currently being performed; I 
didn't use the value of "i" in the example above. The problem is, compilers 
start warning on unused variable... See running code here: 
http://cpp.sh/9lot

Obviously there are various ways around this, in particular using the 
traditional for loop does not generate a warning. But range-based for loops 
are superior in many ways, and it would be good to be able to use it in 
this situation. I also think the warning is correct, since there is no way 
for the compiler to know your intention here (maybe you just made a typo 
and intended to use "i"?). Therefore, do you think it would be possible to 
solve this issue by allowing the range variable to be unnamed? Something 
like:

for (int : range(10)) {
    // ...
}

That would also make one's intention clearer.

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/6b4ef651-55b3-4b93-a6ac-574b55c7f759%40isocpp.org.

------=_Part_205_291784764.1464950236859
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I have defined a utility function &quot;range(n)&quot; tha=
t generates a input sequence of integers from 0 to n-1 such that<br><div cl=
ass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-c=
olor: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap=
: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">for</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" 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"> i </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> range</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify">10</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">))</span><spa=
n 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>=C2=A0 =C2=A0 </span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">// ...</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br><br></span><span style=3D"color: #800;" cla=
ss=3D"styled-by-prettify">// Is equivalent to</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">for</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> i </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</s=
pan><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;" c=
lass=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">10</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">++</span><s=
pan style=3D"color: #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-by-prettify">{</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #800;" c=
lass=3D"styled-by-prettify">// ...</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span></div></code></div><br>I think a similar utility is pre=
sent in the range TS, although I do not know it exact name.<br><br>I recent=
ly encountered a situation when I needed to perform &quot;n&quot; iteration=
s, but without caring about &quot;which&quot; iteration is currently being =
performed; I didn&#39;t use the value of &quot;i&quot; in the example above=
.. The problem is, compilers start warning on unused variable... See running=
 code here: http://cpp.sh/9lot<br><br>Obviously there are various ways arou=
nd this, in particular using the traditional for loop does not generate a w=
arning. But range-based for loops are superior in many ways, and it would b=
e good to be able to use it in this situation. I also think the warning is =
correct, since there is no way for the compiler to know your intention here=
 (maybe you just made a typo and intended to use &quot;i&quot;?). Therefore=
, do you think it would be possible to solve this issue by allowing the ran=
ge variable to be unnamed? Something like:<br><br><div class=3D"prettyprint=
" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187=
, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><co=
de class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color=
: #008;" class=3D"styled-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"style=
d-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">:=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> range</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span =
style=3D"color: #066;" class=3D"styled-by-prettify">10</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;" cl=
ass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #800;" cla=
ss=3D"styled-by-prettify">// ...</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span></div></code></div><br>That would also make one&#39;s i=
ntention clearer.<br></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/6b4ef651-55b3-4b93-a6ac-574b55c7f759%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6b4ef651-55b3-4b93-a6ac-574b55c7f759=
%40isocpp.org</a>.<br />

------=_Part_205_291784764.1464950236859--

------=_Part_204_1560168322.1464950236858--

.
