Topic: Range-fors with intialisers too?


Author: Thiago Macieira <thiago@macieira.org>
Date: Fri, 24 Jun 2016 21:09:31 -0700
Raw View
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0305r0.html
 (If statement with initializer) introduces the following syntax:

 if ( for-init-statement condition ) statement

The paper talks about using it for switch too but says that it is not
proposing then. Let's say we accept that the benefit would be small.

Regular while and for loops already have init statements.

The one missing is the range for. Could we have the following?

 for ( for-init-statement for-range-declaration : for-range-initializer)

That would allow code like:

 for (auto list = get_list(); auto entry : list) {
  use_both(entry, list);
 }

Provided this new extension is worded properly, it would also solve the
problem of the dangling temporaries that the current ranged for calls for.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

--
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/2261702.Njzz9c7VWv%40tjmaciei-mobl1.

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Fri, 24 Jun 2016 21:40:31 -0700 (PDT)
Raw View
------=_Part_2525_1930376218.1466829631816
Content-Type: multipart/alternative;
 boundary="----=_Part_2526_876588285.1466829631816"

------=_Part_2526_876588285.1466829631816
Content-Type: text/plain; charset=UTF-8

On Saturday, June 25, 2016 at 12:09:34 AM UTC-4, Thiago Macieira wrote:
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0305r0.html
>  (If statement with initializer) introduces the following syntax:
>
>         if ( for-init-statement condition ) statement
>
> The paper talks about using it for switch too but says that it is not
> proposing then. Let's say we accept that the benefit would be small.
>
> Regular while and for loops already have init statements.
>

Since when do while loops have init statements? Or are you just talking
about `for` loops that don't have an increment statement?

--
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/ce3a074f-a3ea-4728-a134-aad57f306950%40isocpp.org.

------=_Part_2526_876588285.1466829631816
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Saturday, June 25, 2016 at 12:09:34 AM UTC-4, Thiago Ma=
cieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><a href=3D"http:/=
/www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0305r0.html" target=3D"_=
blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.google.c=
om/url?q\x3dhttp%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpap=
ers%2F2016%2Fp0305r0.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF95advE2C=
XM1cgqRxc8C8j3r7sFw&#39;;return true;" onclick=3D"this.href=3D&#39;http://w=
ww.google.com/url?q\x3dhttp%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2=
Fdocs%2Fpapers%2F2016%2Fp0305r0.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQj=
CNF95advE2CXM1cgqRxc8C8j3r7sFw&#39;;return true;">http://www.open-std.org/j=
tc1/<wbr>sc22/wg21/docs/papers/2016/<wbr>p0305r0.html</a>
<br>=C2=A0(If statement with initializer) introduces the following syntax:
<br>
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if ( for-init-statement=
 condition ) statement
<br>
<br>The paper talks about using it for switch too but says that it is not=
=20
<br>proposing then. Let&#39;s say we accept that the benefit would be small=
..
<br>
<br>Regular while and for loops already have init statements.<br></blockquo=
te><div><br>Since when do while loops have init statements? Or are you just=
 talking about `for` loops that don&#39;t have an increment statement?</div=
><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/ce3a074f-a3ea-4728-a134-aad57f306950%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ce3a074f-a3ea-4728-a134-aad57f306950=
%40isocpp.org</a>.<br />

------=_Part_2526_876588285.1466829631816--

------=_Part_2525_1930376218.1466829631816--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Fri, 24 Jun 2016 21:52:15 -0700
Raw View
On sexta-feira, 24 de junho de 2016 21:40:31 PDT Nicol Bolas wrote:
> On Saturday, June 25, 2016 at 12:09:34 AM UTC-4, Thiago Macieira wrote:
> > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0305r0.html
> >
> >  (If statement with initializer) introduces the following syntax:
> >         if ( for-init-statement condition ) statement
> >
> > The paper talks about using it for switch too but says that it is not
> > proposing then. Let's say we accept that the benefit would be small.
> >
> > Regular while and for loops already have init statements.
>
> Since when do while loops have init statements? Or are you just talking
> about `for` loops that don't have an increment statement?

I was thinking of how you can declare variables in them, but I didn't think it
through. It's the same syntax as plain old if, which means that anything that
applies to if should apply to while too.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

--
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/4023757.Ubk7NOhlWs%40tjmaciei-mobl1.

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Fri, 24 Jun 2016 21:53:34 -0700
Raw View
On sexta-feira, 24 de junho de 2016 21:52:15 PDT Thiago Macieira wrote:
> On sexta-feira, 24 de junho de 2016 21:40:31 PDT Nicol Bolas wrote:
> > On Saturday, June 25, 2016 at 12:09:34 AM UTC-4, Thiago Macieira wrote:
> > > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0305r0.html
> > >
> > >  (If statement with initializer) introduces the following syntax:
> > >         if ( for-init-statement condition ) statement
> > >
> > > The paper talks about using it for switch too but says that it is not
> > > proposing then. Let's say we accept that the benefit would be small.
> > >
> > > Regular while and for loops already have init statements.
> >
> > Since when do while loops have init statements? Or are you just talking
> > about `for` loops that don't have an increment statement?
>
> I was thinking of how you can declare variables in them, but I didn't think
> it through. It's the same syntax as plain old if, which means that anything
> that applies to if should apply to while too.

Thinking it a little more through, we don't need it for while, as it can be
converted to a for:

 for ( init; loop_condition; )

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

--
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/1582281.NR9gXGSu2N%40tjmaciei-mobl1.

.


Author: Zhihao Yuan <zy@miator.net>
Date: Sat, 25 Jun 2016 00:11:34 -0500
Raw View
On Fri, Jun 24, 2016 at 11:09 PM, Thiago Macieira <thiago@macieira.org> wrote:
>
>         for (auto list = get_list(); auto entry : list) {
>                 use_both(entry, list);
>         }
>

Looks hard to read :(

  if (auto list = get_list()) {
    for (auto entry : list)
      use_both(entry, list);
  }

Looks clearer to me.

> Provided this new extension is worded properly, it would also solve the
> problem of the dangling temporaries that the current ranged for calls for.

I think we should just solve it.

--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://blog.miator.net/

--
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/CAGsORuCReeUz%3D_%3Dze6qAkQzYVe05y6JQHLvvBud6YJDgsaWUng%40mail.gmail.com.

.


Author: Zhihao Yuan <zy@miator.net>
Date: Sat, 25 Jun 2016 00:25:24 -0500
Raw View
On Sat, Jun 25, 2016 at 12:11 AM, Zhihao Yuan <zy@miator.net> wrote:
>
>   if (auto list = get_list()) {
>     for (auto entry : list)
>       use_both(entry, list);
>   }

Oh this is _init-statement_ not _condition_, then

  #define with(init) if(init; true)

  with (auto list = get_list()) {
    for (auto entry : list)
      use_both(entry, list);
  }

--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://blog.miator.net/

--
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/CAGsORuBRhYEDOhAaOQUJwVDOtuu6rz3pRn%3Ddrv44Y2j9MsvrMQ%40mail.gmail.com.

.