Topic: Borrowing from Python's: "property" & "for... else


Author: Phil Bouchard <philippeb8@gmail.com>
Date: Sun, 12 Aug 2018 21:50:00 -0700 (PDT)
Raw View
------=_Part_1295_73466732.1534135800914
Content-Type: multipart/alternative;
 boundary="----=_Part_1296_712759909.1534135800914"

------=_Part_1296_712759909.1534135800914
Content-Type: text/plain; charset="UTF-8"

Greetings,

1)
While studying Python, it came to my attention the necessity for C++ to
have clean getters and setters. When you set a variable then you need most
of the time to assert the value is correct, etc.

Qt's solution to this is to use the traditional getValue() & setValue()
using camelback's syntax. Python got these properties attributes that are a
little bit cleaner.

But the real solution should be to have a clean and elegant syntax for
setters and getters that are object-oriented at the same time. Please see
the attached example for a proposed solution.

2)
The following example speaks for itself:

for (int i = 0; i < 0; ++ i)
    cout << ".";
else
    cout << "Not found!" << endl;


Regards,
-Phil
www.fornux.com

--
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/f0838773-850c-4c2b-8c73-ce1db1428ce0%40isocpp.org.

------=_Part_1296_712759909.1534135800914
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Greetings,<div><br></div><div>1)</div><div>While studying =
Python, it came to my attention the necessity for C++ to have clean getters=
 and setters. When you set a variable then you need most of the time to ass=
ert the value=C2=A0is correct, etc.=C2=A0</div><div><br></div><div>Qt&#39;s=
 solution to this is to use the traditional getValue() &amp; setValue() usi=
ng camelback&#39;s syntax. Python got these properties attributes that are =
a little bit cleaner.=C2=A0</div><div><br></div><div>But the real solution =
should be to have a clean and elegant syntax for setters and getters that a=
re object-oriented at the same time. Please see the attached example for a =
proposed solution.</div><div><br></div><div>2)</div><div>The following exam=
ple speaks for itself:</div><div><br></div><div>for (int i =3D 0; i &lt; 0;=
 ++ i)</div><div>=C2=A0 =C2=A0 cout=C2=A0&lt;&lt; &quot;.&quot;;</div><div>=
else</div><div>=C2=A0 =C2=A0 cout=C2=A0&lt;&lt; &quot;Not found!&quot; &lt;=
&lt; endl;</div><div><br></div><div><br></div><div>Regards,</div><div>-Phil=
</div><div>www.fornux.com</div></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/f0838773-850c-4c2b-8c73-ce1db1428ce0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f0838773-850c-4c2b-8c73-ce1db1428ce0=
%40isocpp.org</a>.<br />

------=_Part_1296_712759909.1534135800914--

------=_Part_1295_73466732.1534135800914
Content-Type: text/x-c++src; charset=US-ASCII; name=oomembers.cpp
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=oomembers.cpp
X-Attachment-Id: c08f6db8-7d40-42f8-8feb-65d332a4cec3
Content-ID: <c08f6db8-7d40-42f8-8feb-65d332a4cec3>

#include <iostream>

using namespace std;


template <typename T>
    struct property
    {
        T value;

        T & operator () () { value; }
        T const & operator () () const { value; }
        T & operator () (T const & value_) { return value = value_; }
    };

struct A
{
    struct : property<int>
    {
        using property<int>::operator ();
        int & operator () (int const & value_) { return value = value_ < 0 ? 0 : value_ > 10 ? 10 : value_; }
    } range_short;

    struct : property<int>
    {
        using property<int>::operator ();
        int & operator () (int const & value_) { return value = value_ < 0 ? 0 : value_ > 1000 ? 1000 : value_; }
    } range_long;
};


int main()
{
    A a;
    a.range_short(20);
    a.range_long(9999);
    cout << a.range_short() << endl;
    cout << a.range_long() << endl;
}

------=_Part_1295_73466732.1534135800914--

.


Author: Jake Arkinstall <jake.arkinstall@gmail.com>
Date: Mon, 13 Aug 2018 08:49:47 +0100
Raw View
--000000000000eb972a05734c560b
Content-Type: text/plain; charset="UTF-8"

What C++ has that python doesn't is a brilliant type system. If you have a
requirement for a parameter you can provide a type for it, with
constructors allowing a validating conversion from an input type. In this
way, you don't need a getter or setter - you can override assignment and
provide casts.

A benefit of this approach is that validation can be done exactly once -
you can pass an EmailAddress object around knowing it necessarily
represents a validated email address, only doing validation upon assignment
from an unvalidated type (a string). A getter/setter wherever you have an
email address in a class, storing it as a string, means that the validation
is done every time it is passed to any class - even if it has already been
validated.


The for-else is interesting. I presume

for(init; condition; increment){
    statement1;
}else{
    statement2;
}

would be equivalent to:

if(init; condition){
    do{
          statement1;
          increment;
    } while(condition);
}else{
    statement2;
}

--
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/CAC%2B0CCNP2rqcgHFNSr_A%2BWmWUdJKAFqxxcXb-c-5tjTxK7VZKA%40mail.gmail.com.

--000000000000eb972a05734c560b
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">What C++ has that python doesn&#39;t is a brilliant type =
system. If you have a requirement for a parameter you can provide a type fo=
r it, with constructors allowing a validating conversion from an input type=
.. In this way, you don&#39;t need a getter or setter - you can override ass=
ignment and provide casts.<div dir=3D"auto"><br></div><div dir=3D"auto">A b=
enefit of this approach is that validation can be done exactly once - you c=
an pass an EmailAddress object around knowing it necessarily represents a v=
alidated email address, only doing validation upon assignment from an unval=
idated type (a string). A getter/setter wherever you have an email address =
in a class, storing it as a string, means that the validation is done every=
 time it is passed to any class - even if it has already been validated.</d=
iv><div dir=3D"auto"><br></div><div dir=3D"auto"><br></div><div dir=3D"auto=
">The for-else is interesting. I presume</div><div dir=3D"auto"><br></div><=
div dir=3D"auto">for(init; condition; increment){</div><div dir=3D"auto">=
=C2=A0 =C2=A0 statement1;</div><div dir=3D"auto">}else{</div><div dir=3D"au=
to">=C2=A0 =C2=A0 statement2;</div><div dir=3D"auto">}</div><div dir=3D"aut=
o"><br></div><div dir=3D"auto">would be equivalent to:</div><div dir=3D"aut=
o"><br></div><div dir=3D"auto">if(init; condition){</div><div dir=3D"auto">=
=C2=A0 =C2=A0 do{</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 statement1;</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 incr=
ement;</div><div dir=3D"auto">=C2=A0 =C2=A0 } while(condition);</div><div d=
ir=3D"auto">}else{</div><div dir=3D"auto">=C2=A0 =C2=A0 statement2;</div><d=
iv dir=3D"auto">}</div><div dir=3D"auto"><br></div></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/CAC%2B0CCNP2rqcgHFNSr_A%2BWmWUdJKAFqx=
xcXb-c-5tjTxK7VZKA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCNP2r=
qcgHFNSr_A%2BWmWUdJKAFqxxcXb-c-5tjTxK7VZKA%40mail.gmail.com</a>.<br />

--000000000000eb972a05734c560b--

.


Author: Phil Bouchard <philippeb8@gmail.com>
Date: Mon, 13 Aug 2018 17:58:17 -0700 (PDT)
Raw View
------=_Part_1735_1961266200.1534208297991
Content-Type: multipart/alternative;
 boundary="----=_Part_1736_310172946.1534208297991"

------=_Part_1736_310172946.1534208297991
Content-Type: text/plain; charset="UTF-8"



On Monday, August 13, 2018 at 3:49:58 AM UTC-4, Jake Arkinstall wrote:
>
> What C++ has that python doesn't is a brilliant type system. If you have a
> requirement for a parameter you can provide a type for it, with
> constructors allowing a validating conversion from an input type. In this
> way, you don't need a getter or setter - you can override assignment and
> provide casts.
>
> A benefit of this approach is that validation can be done exactly once -
> you can pass an EmailAddress object around knowing it necessarily
> represents a validated email address, only doing validation upon assignment
> from an unvalidated type (a string). A getter/setter wherever you have an
> email address in a class, storing it as a string, means that the validation
> is done every time it is passed to any class - even if it has already been
> validated.
>
>
Ah you mean like the example attached. I agree it is even cleaner this way!


> The for-else is interesting. I presume
>
> for(init; condition; increment){
>     statement1;
> }else{
>     statement2;
> }
>
> would be equivalent to:
>
> if(init; condition){
>     do{
>           statement1;
>           increment;
>     } while(condition);
> }else{
>     statement2;
> }
>
>
More like:

int i;

for (i = 0; i < 10; ++ i)
    cout << ".";

if (i >= 10)
    cout << "Not found!" << endl;


Regards,
-Phil

--
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/17e699b0-a238-4e9a-a6be-0424ef96d910%40isocpp.org.

------=_Part_1736_310172946.1534208297991
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Monday, August 13, 2018 at 3:49:58 AM UTC-4, Ja=
ke Arkinstall wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"auto">What C++ has that python doesn&#39;t is a brilliant type system. =
If you have a requirement for a parameter you can provide a type for it, wi=
th constructors allowing a validating conversion from an input type. In thi=
s way, you don&#39;t need a getter or setter - you can override assignment =
and provide casts.<div dir=3D"auto"><br></div><div dir=3D"auto">A benefit o=
f this approach is that validation can be done exactly once - you can pass =
an EmailAddress object around knowing it necessarily represents a validated=
 email address, only doing validation upon assignment from an unvalidated t=
ype (a string). A getter/setter wherever you have an email address in a cla=
ss, storing it as a string, means that the validation is done every time it=
 is passed to any class - even if it has already been validated.</div><div =
dir=3D"auto"><br></div></div></blockquote><div><br></div><div>Ah you mean l=
ike the example attached. I agree it is even cleaner this way!</div><div>=
=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"auto">=
<div dir=3D"auto"></div><div dir=3D"auto">The for-else is interesting. I pr=
esume</div><div dir=3D"auto"><br></div><div dir=3D"auto">for(init; conditio=
n; increment){</div><div dir=3D"auto">=C2=A0 =C2=A0 statement1;</div><div d=
ir=3D"auto">}else{</div><div dir=3D"auto">=C2=A0 =C2=A0 statement2;</div><d=
iv dir=3D"auto">}</div><div dir=3D"auto"><br></div><div dir=3D"auto">would =
be equivalent to:</div><div dir=3D"auto"><br></div><div dir=3D"auto">if(ini=
t; condition){</div><div dir=3D"auto">=C2=A0 =C2=A0 do{</div><div dir=3D"au=
to">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 statement1;</div><div dir=3D"auto">=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 increment;</div><div dir=3D"auto">=C2=A0=
 =C2=A0 } while(condition);</div><div dir=3D"auto">}else{</div><div dir=3D"=
auto">=C2=A0 =C2=A0 statement2;</div><div dir=3D"auto">}</div><div dir=3D"a=
uto"><br></div></div></blockquote><div><br></div><div>More like:<br><br>int=
 i;<br><div><br></div><div>for (i =3D 0; i &lt; 10; ++ i)</div><div>=C2=A0 =
=C2=A0 cout=C2=A0&lt;&lt; &quot;.&quot;;</div><div><br></div><div>if (i &gt=
;=3D 10)</div><div>=C2=A0 =C2=A0 cout=C2=A0&lt;&lt; &quot;Not found!&quot; =
&lt;&lt; endl;<br></div><div><br></div></div><div><br></div><div>Regards,</=
div><div>-Phil</div></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/17e699b0-a238-4e9a-a6be-0424ef96d910%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/17e699b0-a238-4e9a-a6be-0424ef96d910=
%40isocpp.org</a>.<br />

------=_Part_1736_310172946.1534208297991--

------=_Part_1735_1961266200.1534208297991
Content-Type: text/x-c++src; charset=US-ASCII; name=oomembers.cpp
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=oomembers.cpp
X-Attachment-Id: 730c2c16-8b37-42a6-9d4b-4774f7ecd734
Content-ID: <730c2c16-8b37-42a6-9d4b-4774f7ecd734>

#include <iostream>

using namespace std;


template <typename T>
    struct property
    {
        T value;

        operator T const & () { return value; }
        T const & operator = (property const & a) { return value = a.value; }
    };

struct A
{
    struct range_short_t : property<int>
    {
        range_short_t(int const & value_) { value = value_ < 0 ? 0 : value_ > 10 ? 10 : value_; }
    } range_short = int();

    struct range_long_t : property<int>
    {
        range_long_t(int const & value_) { value = value_ < 0 ? 0 : value_ > 1000 ? 1000 : value_; }
    } range_long = int();
};


int main()
{
    A a;
    a.range_short = 20;
    a.range_long = 9999;
    cout << a.range_short << endl;
    cout << a.range_long << endl;
}

------=_Part_1735_1961266200.1534208297991--

.


Author: Tony V E <tvaneerd@gmail.com>
Date: Tue, 14 Aug 2018 11:16:48 +0200
Raw View
<html><head></head><body lang=3D"en-US" style=3D"background-color: rgb(255,=
 255, 255); line-height: initial;">                                        =
                                              <div style=3D"width: 100%; fo=
nt-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif=
; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, =
255, 255);">No,IIUC, &nbsp;the for-else typically (ie python) enters the el=
se if the for loop reaches the end.</div><div style=3D"width: 100%; font-si=
ze: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; col=
or: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, =
255);">It seems odd, but the idea is:</div><div style=3D"width: 100%; font-=
size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; c=
olor: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255=
, 255);"><br></div><div style=3D"width: 100%; font-size: initial; font-fami=
ly: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); =
text-align: initial; background-color: rgb(255, 255, 255);">for (auto stran=
d : haystack)</div><div style=3D"width: 100%; font-size: initial; font-fami=
ly: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); =
text-align: initial; background-color: rgb(255, 255, 255);">{</div><div sty=
le=3D"width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', s=
ans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; backgr=
ound-color: rgb(255, 255, 255);">&nbsp; &nbsp;if (strand =3D=3D needle)</di=
v><div style=3D"width: 100%; font-size: initial; font-family: Calibri, 'Sla=
te Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initi=
al; background-color: rgb(255, 255, 255);">&nbsp; &nbsp; &nbsp; &nbsp; foun=
d_it(strand);</div><div style=3D"width: 100%; font-size: initial; font-fami=
ly: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); =
text-align: initial; background-color: rgb(255, 255, 255);">}</div><div sty=
le=3D"width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', s=
ans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; backgr=
ound-color: rgb(255, 255, 255);">else</div><div style=3D"width: 100%; font-=
size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; c=
olor: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255=
, 255);">&nbsp; &nbsp;not_found();</div><div style=3D"width: 100%; font-siz=
e: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; colo=
r: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 2=
55);"><br></div><div style=3D"width: 100%; font-size: initial; font-family:=
 Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); tex=
t-align: initial; background-color: rgb(255, 255, 255);">I think there has =
already been a proposal for this. Not sure what happened. Most likely "we n=
eed another flow control like we need another hole in our heads".</div><div=
 style=3D"width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro=
', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; ba=
ckground-color: rgb(255, 255, 255);"><br></div>                            =
                                                                           =
                              <div style=3D"width: 100%; font-size: initial=
; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31,=
 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"><br>=
</div>                                                                     =
                                                                           =
                                                   <div style=3D"font-size:=
 initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color:=
 rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255=
);">Sent&nbsp;from&nbsp;my&nbsp;BlackBerry&nbsp;portable&nbsp;Babbage&nbsp;=
Device</div>                                                               =
                                                                           =
                                        <table width=3D"100%" style=3D"back=
ground-color:white;border-spacing:0px;"> <tbody><tr><td colspan=3D"2" style=
=3D"font-size: initial; text-align: initial; background-color: rgb(255, 255=
, 255);">                           <div style=3D"border-style: solid none =
none; border-top-color: rgb(181, 196, 223); border-top-width: 1pt; padding:=
 3pt 0in 0in; font-family: Tahoma, 'BB Alpha Sans', 'Slate Pro'; font-size:=
 10pt;">  <div><b>From: </b>Jake Arkinstall</div><div><b>Sent: </b>Monday, =
August 13, 2018 9:49 AM</div><div><b>To: </b>std-proposals@isocpp.org</div>=
<div><b>Reply To: </b>std-proposals@isocpp.org</div><div><b>Subject: </b>Re=
: [std-proposals] Borrowing from Python's: "property" &amp; "for... else"</=
div></div></td></tr></tbody></table><div style=3D"border-style: solid none =
none; border-top-color: rgb(186, 188, 209); border-top-width: 1pt; font-siz=
e: initial; text-align: initial; background-color: rgb(255, 255, 255);"></d=
iv><br><div id=3D"_originalContent" style=3D""><div dir=3D"auto">What C++ h=
as that python doesn't is a brilliant type system. If you have a requiremen=
t for a parameter you can provide a type for it, with constructors allowing=
 a validating conversion from an input type. In this way, you don't need a =
getter or setter - you can override assignment and provide casts.<div dir=
=3D"auto"><br></div><div dir=3D"auto">A benefit of this approach is that va=
lidation can be done exactly once - you can pass an EmailAddress object aro=
und knowing it necessarily represents a validated email address, only doing=
 validation upon assignment from an unvalidated type (a string). A getter/s=
etter wherever you have an email address in a class, storing it as a string=
, means that the validation is done every time it is passed to any class - =
even if it has already been validated.</div><div dir=3D"auto"><br></div><di=
v dir=3D"auto"><br></div><div dir=3D"auto">The for-else is interesting. I p=
resume</div><div dir=3D"auto"><br></div><div dir=3D"auto">for(init; conditi=
on; increment){</div><div dir=3D"auto">&nbsp; &nbsp; statement1;</div><div =
dir=3D"auto">}else{</div><div dir=3D"auto">&nbsp; &nbsp; statement2;</div><=
div dir=3D"auto">}</div><div dir=3D"auto"><br></div><div dir=3D"auto">would=
 be equivalent to:</div><div dir=3D"auto"><br></div><div dir=3D"auto">if(in=
it; condition){</div><div dir=3D"auto">&nbsp; &nbsp; do{</div><div dir=3D"a=
uto">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; statement1;</div><div dir=3D"auto">=
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; increment;</div><div dir=3D"auto">&nbsp;=
 &nbsp; } while(condition);</div><div dir=3D"auto">}else{</div><div dir=3D"=
auto">&nbsp; &nbsp; statement2;</div><div dir=3D"auto">}</div><div dir=3D"a=
uto"><br></div></div>

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" 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/CAC%2B0CCNP2rqcgHFNSr_A%2BWmWUdJKAFqx=
xcXb-c-5tjTxK7VZKA%40mail.gmail.com?utm_medium=3Demail&amp;utm_source=3Dfoo=
ter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CC=
NP2rqcgHFNSr_A%2BWmWUdJKAFqxxcXb-c-5tjTxK7VZKA%40mail.gmail.com</a>.<br>
<br><!--end of _originalContent --></div></body></html>

<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/20180814091648.5202000.51992.60301%40=
gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com=
/a/isocpp.org/d/msgid/std-proposals/20180814091648.5202000.51992.60301%40gm=
ail.com</a>.<br />

.


Author: Furkan Usta <furkanusta17@gmail.com>
Date: Tue, 14 Aug 2018 18:06:51 +0300
Raw View
--000000000000795b75057366910a
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

I think intention of for..else is might not be apparent since it is not as
common in other languages.

Python-3 documentation states that
> Loop statements may have an else clause; it is executed when the loop
terminates through exhaustion of the list (with for
<https://docs.python.org/3/reference/compound_stmts.html#for>) or when the
condition becomes false (with while
<https://docs.python.org/3/reference/compound_stmts.html#while>), but not
when the loop is terminated by a break
<https://docs.python.org/3/reference/simple_stmts.html#break> statement

From this explanation neither this

if(init; condition){
>     do{
>           statement1;
>           increment;
>     } while(condition);
> }else{
>     statement2;
> }
>

Nor this

> int i;
> for (i =3D 0; i < 10; ++ i)
>     cout << ".";
> if (i >=3D 10)
>     cout << "Not found!" << endl;
>

Nor this:

> for (auto strand : haystack) {
>    if (strand =3D=3D needle)
>         found_it(strand);
> }
> else
>    not_found();
>

Seems correct.
First one doesn't check exhaustion, second one doesn't check initial
condition. Third one does not 'break', if we add break after finding one,
than that means we cannot check for multiple occurrences.
Sure, we do not need to copy Python exactly but this might give an idea how
a seemingly simple statement can be interpreted in many ways.

By the way existing proposal is/was P0082

- Furkan

Tony V E <tvaneerd@gmail.com>, 14 A=C4=9Fu 2018 Sal, 12:16 tarihinde =C5=9F=
unu yazd=C4=B1:

> No,IIUC,  the for-else typically (ie python) enters the else if the for
> loop reaches the end.
> It seems odd, but the idea is:
>
> for (auto strand : haystack)
> {
>    if (strand =3D=3D needle)
>         found_it(strand);
> }
> else
>    not_found();
>
> I think there has already been a proposal for this. Not sure what
> happened. Most likely "we need another flow control like we need another
> hole in our heads".
>
>
> Sent from my BlackBerry portable Babbage Device
> *From: *Jake Arkinstall
> *Sent: *Monday, August 13, 2018 9:49 AM
> *To: *std-proposals@isocpp.org
> *Reply To: *std-proposals@isocpp.org
> *Subject: *Re: [std-proposals] Borrowing from Python's: "property" &
> "for... else"
>
> What C++ has that python doesn't is a brilliant type system. If you have =
a
> requirement for a parameter you can provide a type for it, with
> constructors allowing a validating conversion from an input type. In this
> way, you don't need a getter or setter - you can override assignment and
> provide casts.
>
> A benefit of this approach is that validation can be done exactly once -
> you can pass an EmailAddress object around knowing it necessarily
> represents a validated email address, only doing validation upon assignme=
nt
> from an unvalidated type (a string). A getter/setter wherever you have an
> email address in a class, storing it as a string, means that the validati=
on
> is done every time it is passed to any class - even if it has already bee=
n
> validated.
>
>
> The for-else is interesting. I presume
>
> for(init; condition; increment){
>     statement1;
> }else{
>     statement2;
> }
>
> would be equivalent to:
>
> if(init; condition){
>     do{
>           statement1;
>           increment;
>     } while(condition);
> }else{
>     statement2;
> }
>
> --
> 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/CAC%2B0CCNP2=
rqcgHFNSr_A%2BWmWUdJKAFqxxcXb-c-5tjTxK7VZKA%40mail.gmail.com
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCNP=
2rqcgHFNSr_A%2BWmWUdJKAFqxxcXb-c-5tjTxK7VZKA%40mail.gmail.com?utm_medium=3D=
email&utm_source=3Dfooter>
> .
>
> --
> 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/201808140916=
48.5202000.51992.60301%40gmail.com
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/20180814091=
648.5202000.51992.60301%40gmail.com?utm_medium=3Demail&utm_source=3Dfooter>
> .
>

--=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/CA%2BThi2tSMfvMgNCqm_4dZhfSjj%3DS_oHbpkQfHsJfyV0=
PnHTSsw%40mail.gmail.com.

--000000000000795b75057366910a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I think intention of for..else is might not be appare=
nt since it is not as common in other languages.</div><div><br></div><div>P=
ython-3 documentation states that</div><div>&gt;=C2=A0Loop statements may h=
ave an <code class=3D"gmail-docutils gmail-literal gmail-notranslate"><span=
 class=3D"gmail-pre">else</span></code> clause; it is executed when the loo=
p
terminates through exhaustion of the list (with <a class=3D"gmail-reference=
 gmail-internal" href=3D"https://docs.python.org/3/reference/compound_stmts=
..html#for"><code class=3D"gmail-xref gmail-std gmail-std-keyword gmail-docu=
tils gmail-literal gmail-notranslate"><span class=3D"gmail-pre">for</span><=
/code></a>) or when the
condition becomes false (with <a class=3D"gmail-reference gmail-internal" h=
ref=3D"https://docs.python.org/3/reference/compound_stmts.html#while"><code=
 class=3D"gmail-xref gmail-std gmail-std-keyword gmail-docutils gmail-liter=
al gmail-notranslate"><span class=3D"gmail-pre">while</span></code></a>), b=
ut not when the loop is
terminated by a <a class=3D"gmail-reference gmail-internal" href=3D"https:/=
/docs.python.org/3/reference/simple_stmts.html#break"><code class=3D"gmail-=
xref gmail-std gmail-std-keyword gmail-docutils gmail-literal gmail-notrans=
late"><span class=3D"gmail-pre">break</span></code></a> statement</div><div=
><br></div><div>From this explanation neither this</div><div><div dir=3D"au=
to"><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px=
 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D=
"auto">if(init; condition){</div><div dir=3D"auto">=C2=A0 =C2=A0 do{</div><=
div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 statement1;</div><div d=
ir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 increment;</div><div dir=3D"=
auto">=C2=A0 =C2=A0 } while(condition);</div><div dir=3D"auto">}else{</div>=
<div dir=3D"auto">=C2=A0 =C2=A0 statement2;</div><div dir=3D"auto">}</div><=
/blockquote><div dir=3D"auto"><br></div><div>Nor this<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rg=
b(204,204,204);padding-left:1ex">int i;<br><div>for (i =3D 0; i &lt; 10; ++=
 i)</div><div>=C2=A0 =C2=A0 cout=C2=A0&lt;&lt; &quot;.&quot;;</div><div>if =
(i &gt;=3D 10)</div><div>=C2=A0 =C2=A0 cout=C2=A0&lt;&lt; &quot;Not found!&=
quot; &lt;&lt; endl;</div></blockquote><div><br></div><div>Nor this:</div><=
div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bor=
der-left:1px solid rgb(204,204,204);padding-left:1ex"><div style=3D"width:1=
00%;font-size:initial;font-family:Calibri,&quot;Slate Pro&quot;,sans-serif,=
sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255=
,255,255)">for (auto strand : haystack) {</div><div style=3D"width:100%;fon=
t-size:initial;font-family:Calibri,&quot;Slate Pro&quot;,sans-serif,sans-se=
rif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,25=
5)">=C2=A0 =C2=A0if (strand =3D=3D needle)</div><div style=3D"width:100%;fo=
nt-size:initial;font-family:Calibri,&quot;Slate Pro&quot;,sans-serif,sans-s=
erif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,2=
55)">=C2=A0 =C2=A0 =C2=A0 =C2=A0 found_it(strand);</div><div style=3D"width=
:100%;font-size:initial;font-family:Calibri,&quot;Slate Pro&quot;,sans-seri=
f,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(2=
55,255,255)">}</div><div style=3D"width:100%;font-size:initial;font-family:=
Calibri,&quot;Slate Pro&quot;,sans-serif,sans-serif;color:rgb(31,73,125);te=
xt-align:initial;background-color:rgb(255,255,255)">else</div><div style=3D=
"width:100%;font-size:initial;font-family:Calibri,&quot;Slate Pro&quot;,san=
s-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color=
:rgb(255,255,255)">=C2=A0 =C2=A0not_found();</div></blockquote><div><br></d=
iv><div>Seems correct. <br></div><div>First one doesn&#39;t check exhaustio=
n, second one doesn&#39;t check initial condition. Third one does not &#39;=
break&#39;, if we add break after finding one, than that means we cannot ch=
eck for multiple occurrences. <br></div><div>Sure, we do not need to copy P=
ython exactly but this might give an idea how a seemingly simple statement =
can be interpreted in many ways.</div><div><br></div><div>By the way existi=
ng proposal is/was P0082</div><div><br></div><div>- Furkan<br></div> </div>=
</div></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">Tony V E =
&lt;<a href=3D"mailto:tvaneerd@gmail.com">tvaneerd@gmail.com</a>&gt;, 14 A=
=C4=9Fu 2018 Sal, 12:16 tarihinde =C5=9Funu yazd=C4=B1:<br></div><blockquot=
e class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc sol=
id;padding-left:1ex"><div lang=3D"en-US" style=3D"background-color:rgb(255,=
255,255);line-height:initial">                                             =
                                         <div style=3D"width:100%;font-size=
:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;colo=
r:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)">No,I=
IUC, =C2=A0the for-else typically (ie python) enters the else if the for lo=
op reaches the end.</div><div style=3D"width:100%;font-size:initial;font-fa=
mily:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125)=
;text-align:initial;background-color:rgb(255,255,255)">It seems odd, but th=
e idea is:</div><div style=3D"width:100%;font-size:initial;font-family:Cali=
bri,&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);text-ali=
gn:initial;background-color:rgb(255,255,255)"><br></div><div style=3D"width=
:100%;font-size:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,=
sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255=
,255,255)">for (auto strand : haystack)</div><div style=3D"width:100%;font-=
size:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;=
color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)">=
{</div><div style=3D"width:100%;font-size:initial;font-family:Calibri,&#39;=
Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);text-align:initia=
l;background-color:rgb(255,255,255)">=C2=A0 =C2=A0if (strand =3D=3D needle)=
</div><div style=3D"width:100%;font-size:initial;font-family:Calibri,&#39;S=
late Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial=
;background-color:rgb(255,255,255)">=C2=A0 =C2=A0 =C2=A0 =C2=A0 found_it(st=
rand);</div><div style=3D"width:100%;font-size:initial;font-family:Calibri,=
&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);text-align:i=
nitial;background-color:rgb(255,255,255)">}</div><div style=3D"width:100%;f=
ont-size:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-se=
rif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,25=
5)">else</div><div style=3D"width:100%;font-size:initial;font-family:Calibr=
i,&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);text-align=
:initial;background-color:rgb(255,255,255)">=C2=A0 =C2=A0not_found();</div>=
<div style=3D"width:100%;font-size:initial;font-family:Calibri,&#39;Slate P=
ro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;backg=
round-color:rgb(255,255,255)"><br></div><div style=3D"width:100%;font-size:=
initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;color=
:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)">I thi=
nk there has already been a proposal for this. Not sure what happened. Most=
 likely &quot;we need another flow control like we need another hole in our=
 heads&quot;.</div><div style=3D"width:100%;font-size:initial;font-family:C=
alibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);text-=
align:initial;background-color:rgb(255,255,255)"><br></div>                =
                                                                           =
                                          <div style=3D"width:100%;font-siz=
e:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;col=
or:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"><br=
></div>                                                                    =
                                                                           =
                                                    <div style=3D"font-size=
:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;colo=
r:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)">Sent=
=C2=A0from=C2=A0my=C2=A0BlackBerry=C2=A0portable=C2=A0Babbage=C2=A0Device</=
div>                                                                       =
                                                                           =
                                <table width=3D"100%" style=3D"background-c=
olor:white;border-spacing:0px"> <tbody><tr><td colspan=3D"2" style=3D"font-=
size:initial;text-align:initial;background-color:rgb(255,255,255)">        =
                   <div style=3D"border-style:solid none none;border-top-co=
lor:rgb(181,196,223);border-top-width:1pt;padding:3pt 0in 0in;font-family:T=
ahoma,&#39;BB Alpha Sans&#39;,&#39;Slate Pro&#39;;font-size:10pt">  <div><b=
>From: </b>Jake Arkinstall</div><div><b>Sent: </b>Monday, August 13, 2018 9=
:49 AM</div><div><b>To: </b><a href=3D"mailto:std-proposals@isocpp.org" tar=
get=3D"_blank">std-proposals@isocpp.org</a></div><div><b>Reply To: </b><a h=
ref=3D"mailto:std-proposals@isocpp.org" target=3D"_blank">std-proposals@iso=
cpp.org</a></div><div><b>Subject: </b>Re: [std-proposals] Borrowing from Py=
thon&#39;s: &quot;property&quot; &amp; &quot;for... else&quot;</div></div><=
/td></tr></tbody></table><div style=3D"border-style:solid none none;border-=
top-color:rgb(186,188,209);border-top-width:1pt;font-size:initial;text-alig=
n:initial;background-color:rgb(255,255,255)"></div><br><div id=3D"m_3193351=
655924242053_originalContent"><div dir=3D"auto">What C++ has that python do=
esn&#39;t is a brilliant type system. If you have a requirement for a param=
eter you can provide a type for it, with constructors allowing a validating=
 conversion from an input type. In this way, you don&#39;t need a getter or=
 setter - you can override assignment and provide casts.<div dir=3D"auto"><=
br></div><div dir=3D"auto">A benefit of this approach is that validation ca=
n be done exactly once - you can pass an EmailAddress object around knowing=
 it necessarily represents a validated email address, only doing validation=
 upon assignment from an unvalidated type (a string). A getter/setter where=
ver you have an email address in a class, storing it as a string, means tha=
t the validation is done every time it is passed to any class - even if it =
has already been validated.</div><div dir=3D"auto"><br></div><div dir=3D"au=
to"><br></div><div dir=3D"auto">The for-else is interesting. I presume</div=
><div dir=3D"auto"><br></div><div dir=3D"auto">for(init; condition; increme=
nt){</div><div dir=3D"auto">=C2=A0 =C2=A0 statement1;</div><div dir=3D"auto=
">}else{</div><div dir=3D"auto">=C2=A0 =C2=A0 statement2;</div><div dir=3D"=
auto">}</div><div dir=3D"auto"><br></div><div dir=3D"auto">would be equival=
ent to:</div><div dir=3D"auto"><br></div><div dir=3D"auto">if(init; conditi=
on){</div><div dir=3D"auto">=C2=A0 =C2=A0 do{</div><div dir=3D"auto">=C2=A0=
 =C2=A0 =C2=A0 =C2=A0 =C2=A0 statement1;</div><div dir=3D"auto">=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 increment;</div><div dir=3D"auto">=C2=A0 =C2=A0 } =
while(condition);</div><div dir=3D"auto">}else{</div><div dir=3D"auto">=C2=
=A0 =C2=A0 statement2;</div><div dir=3D"auto">}</div><div dir=3D"auto"><br>=
</div></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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/CAC%2B0CCNP2rqcgHFNSr_A%2BWmWUdJKAFqx=
xcXb-c-5tjTxK7VZKA%40mail.gmail.com?utm_medium=3Demail&amp;utm_source=3Dfoo=
ter" target=3D"_blank">https://groups.google.com/a/isocpp.org/d/msgid/std-p=
roposals/CAC%2B0CCNP2rqcgHFNSr_A%2BWmWUdJKAFqxxcXb-c-5tjTxK7VZKA%40mail.gma=
il.com</a>.<br>
<br></div></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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/20180814091648.5202000.51992.60301%40=
gmail.com?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/20180814091648.52=
02000.51992.60301%40gmail.com</a>.<br>
</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/CA%2BThi2tSMfvMgNCqm_4dZhfSjj%3DS_oHb=
pkQfHsJfyV0PnHTSsw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CA%2BThi2tSMf=
vMgNCqm_4dZhfSjj%3DS_oHbpkQfHsJfyV0PnHTSsw%40mail.gmail.com</a>.<br />

--000000000000795b75057366910a--

.


Author: Barry Revzin <barry.revzin@gmail.com>
Date: Tue, 14 Aug 2018 10:10:20 -0700 (PDT)
Raw View
------=_Part_1959_1459964225.1534266621057
Content-Type: multipart/alternative;
 boundary="----=_Part_1960_181435057.1534266621057"

------=_Part_1960_181435057.1534266621057
Content-Type: text/plain; charset="UTF-8"



On Tuesday, August 14, 2018 at 4:16:53 AM UTC-5, Tony V E wrote:
>
> No,IIUC,  the for-else typically (ie python) enters the else if the for
> loop reaches the end.
> It seems odd, but the idea is:
>
> for (auto strand : haystack)
> {
>    if (strand == needle)
>         found_it(strand);
> }
> else
>    not_found();
>
> I think there has already been a proposal for this. Not sure what
> happened. Most likely "we need another flow control like we need another
> hole in our heads".
>

A problem with for/else is that this code (intentionally unformatted):

if (...)
for (...)
s1;
else
s2;

changes from the else being attached to the outer if (the only thing it
could be attached to today) to being attached to the inner for (which is
now closer).

--
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/c0eff3b7-2168-4228-9759-18b4b568cb8b%40isocpp.org.

------=_Part_1960_181435057.1534266621057
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Tuesday, August 14, 2018 at 4:16:53 AM UTC-5, T=
ony V E wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div lang=3D"en-=
US" style=3D"background-color:rgb(255,255,255);line-height:initial">       =
                                                                           =
    <div style=3D"width:100%;font-size:initial;font-family:Calibri,&#39;Sla=
te Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;b=
ackground-color:rgb(255,255,255)">No,IIUC, =C2=A0the for-else typically (ie=
 python) enters the else if the for loop reaches the end.</div><div style=
=3D"width:100%;font-size:initial;font-family:Calibri,&#39;Slate Pro&#39;,sa=
ns-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-colo=
r:rgb(255,255,255)">It seems odd, but the idea is:</div><div style=3D"width=
:100%;font-size:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,=
sans-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255=
,255,255)"><br></div><div style=3D"width:100%;font-size:initial;font-family=
:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);tex=
t-align:initial;background-color:rgb(255,255,255)">for (auto strand : hayst=
ack)</div><div style=3D"width:100%;font-size:initial;font-family:Calibri,&#=
39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);text-align:ini=
tial;background-color:rgb(255,255,255)">{</div><div style=3D"width:100%;fon=
t-size:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-seri=
f;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)=
">=C2=A0 =C2=A0if (strand =3D=3D needle)</div><div style=3D"width:100%;font=
-size:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif=
;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"=
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 found_it(strand);</div><div style=3D"width:100=
%;font-size:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans=
-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255=
,255)">}</div><div style=3D"width:100%;font-size:initial;font-family:Calibr=
i,&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);text-align=
:initial;background-color:rgb(255,255,255)">else</div><div style=3D"width:1=
00%;font-size:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sa=
ns-serif;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,2=
55,255)">=C2=A0 =C2=A0not_found();</div><div style=3D"width:100%;font-size:=
initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;color=
:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"><br><=
/div><div style=3D"width:100%;font-size:initial;font-family:Calibri,&#39;Sl=
ate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;=
background-color:rgb(255,255,255)">I think there has already been a proposa=
l for this. Not sure what happened. Most likely &quot;we need another flow =
control like we need another hole in our heads&quot;.</div></div></blockquo=
te><div><br></div><div>A problem with for/else is that this code (intention=
ally unformatted):</div><div><br></div><div><div class=3D"prettyprint" styl=
e=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187)=
; border-style: solid; border-width: 1px; word-wrap: break-word;"><code cla=
ss=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008=
;" class=3D"styled-by-prettify">if</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">(</span><font color=3D"#000000"><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">...</span></font><span 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"color: #008;" class=3D"style=
d-by-prettify">for</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"><br>s1=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">else</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br>s2</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">;</span></div></code></div><br>chan=
ges from the else being attached to the outer if (the only thing it could b=
e attached to today) to being attached to the inner for (which is now close=
r).=C2=A0<br></div></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/c0eff3b7-2168-4228-9759-18b4b568cb8b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/c0eff3b7-2168-4228-9759-18b4b568cb8b=
%40isocpp.org</a>.<br />

------=_Part_1960_181435057.1534266621057--

------=_Part_1959_1459964225.1534266621057--

.


Author: Jake Arkinstall <jake.arkinstall@gmail.com>
Date: Tue, 14 Aug 2018 19:02:48 +0100
Raw View
--0000000000009555e1057369043b
Content-Type: text/plain; charset="UTF-8"

On Tue, 14 Aug 2018, 01:58 Phil Bouchard, <philippeb8@gmail.com> wrote:

> Ah you mean like the example attached. I agree it is even cleaner this way!
>

Not quite. I'd have a type that guarantees that the value won't be
malformed, or provides an easy way of checking.

#include <iostream>
template<typename T, T min, T max> // template<LessThanComparable
T,...> in C++20struct bounded_type{
    constexpr bounded_type() noexcept
    :
        value{max}
    {}
    constexpr bounded_type(const T& raw) noexcept
    :
        value{clamp(raw)}
    {}
    constexpr bounded_type& operator=(const T& raw) noexcept{
        value = clamp(raw);
        return *this;
    }
    operator T() const noexcept{
        return value;
    }
    bool is_valid() const noexcept{
        return value < max;
    }private:
    T value;
    constexpr static T clamp(const T& input) noexcept{
        std::cout << "VALIDATING" << std::endl;
        return (!(input < min) && input < max) ? input : max;
    }
};
struct A
{
    bounded_type<unsigned char, 0, 11> range_short;
    bounded_type<unsigned short, 0, 1001> range_long;
};struct B{
    bounded_type<unsigned char, 0, 11> range_short;
};

int main()
{
    A a;
    a.range_short = 20;
    a.range_long = 9999;
    std::cout << static_cast<int>(a.range_short) << std::endl;
    std::cout << static_cast<int>(a.range_long) << std::endl;
    B b;
    b.range_short = a.range_short;
    return 0;
}


I simply wouldn't have a getter or setter in a class because I can't think
of a good enough reason to do so. If I want something validated, I want it
done within the type - and then I want to pass that type around anywhere I
want, with each component aware that the type has been validated without
putting the legwork in to do it (and validation never being done more than
once on each value - in the example there are three bounded variables, only
two "VALIDATING" messages).

Perhaps I'm too invested in the strong typing mantra to see the point in
another approach.

But that's just my preference. The down side to my approach is that it
doesn't interact well. A setter (i.e. an assignment) on one variable cannot
check other class variables without coupling them tightly to an owning
class - if you have a set of Cartesian coordinates within the area of a
circle, for example, X and Y cannot be set independently (though to be
honest, I wouldn't want to do that anyway). Languages with in-class getters
and setters usually allow peeking into other class members to validate a
new value.


>
>> The for-else is interesting. I presume
>>
>> for(init; condition; increment){
>>     statement1;
>> }else{
>>     statement2;
>> }
>>
>> would be equivalent to:
>>
>> if(init; condition){
>>     do{
>>           statement1;
>>           increment;
>>     } while(condition);
>> }else{
>>     statement2;
>> }
>>
>>
> More like:
>
> int i;
>
> for (i = 0; i < 10; ++ i)
>     cout << ".";
>
> if (i >= 10)
>     cout << "Not found!" << endl;
>

Doh! Serves me right for not looking at the manual I've been writing python
for years - its a great language for using C++ extensions with - and I
haven't seen that before.

IMO "for...else..." is the dumbest possible syntax for that functionality.
It bears no resemblance to the existing meaning of "else" (which is what I
was going for above), especially in the context of "for".

I'd understand if it were called nobreak.

for(...){
    // search and break upon result
}nobreak{
    // not found
}
// break label

We can already get that functionality, by the way, just by replacing the
"break" keyword with "return" and wrapping it in a lambda, but thats
something people either love or hate.

And then we could do:

for(auto&& i : get_messages()){
    // process message
}else{
    // no messages
}

If anything, it serves to really confuse people who use "for...else..." in
python.

--
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/CAC%2B0CCMX%2BFKCMrnqxu_5rdyFY%2BKor8RSofPtpzLdRWE-xP4TNA%40mail.gmail.com.

--0000000000009555e1057369043b
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"auto"><div class=3D"gmail_quote" dir=3D"auto">=
<div dir=3D"ltr">On Tue, 14 Aug 2018, 01:58 Phil Bouchard, &lt;<a href=3D"m=
ailto:philippeb8@gmail.com" rel=3D"noreferrer noreferrer" target=3D"_blank"=
>philippeb8@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_qu=
ote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex=
"><div dir=3D"ltr">Ah you mean like the example attached. I agree it is eve=
n cleaner this way!</div></blockquote></div><div dir=3D"auto"><br></div><di=
v>Not quite. I&#39;d have a type that guarantees that the value won&#39;t b=
e malformed, or provides an easy way of checking.<br><br><pre style=3D"marg=
in:0px;line-height:125%"><pre style=3D"margin:0px;line-height:125%"><span s=
tyle=3D"color:rgb(188,122,0)">#include &lt;iostream&gt;</span>

<span style=3D"color:rgb(0,128,0);font-weight:bold">template</span><span st=
yle=3D"color:rgb(102,102,102)">&lt;</span><span style=3D"color:rgb(0,128,0)=
;font-weight:bold">typename</span> T, T min, T max<span style=3D"color:rgb(=
102,102,102)">&gt;</span> // template&lt;LessThanComparable T,...&gt; in C+=
+20
<span style=3D"color:rgb(0,128,0);font-weight:bold">struct</span> bounded_t=
ype{
    constexpr bounded_type() noexcept
    <span style=3D"color:rgb(102,102,102)">:</span>
        value{max}
    {}
    constexpr bounded_type(<span style=3D"color:rgb(0,128,0);font-weight:bo=
ld">const</span> T<span style=3D"color:rgb(102,102,102)">&amp;</span> raw) =
noexcept
    <span style=3D"color:rgb(102,102,102)">:</span>
        value{clamp(raw)}
    {}
    constexpr bounded_type<span style=3D"color:rgb(102,102,102)">&amp;</spa=
n> <span style=3D"color:rgb(0,128,0);font-weight:bold">operator</span><span=
 style=3D"color:rgb(102,102,102)">=3D</span>(<span style=3D"color:rgb(0,128=
,0);font-weight:bold">const</span> T<span style=3D"color:rgb(102,102,102)">=
&amp;</span> raw) noexcept{
        value <span style=3D"color:rgb(102,102,102)">=3D</span> clamp(raw);
        <span style=3D"color:rgb(0,128,0);font-weight:bold">return</span> <=
span style=3D"color:rgb(102,102,102)">*</span><span style=3D"color:rgb(0,12=
8,0);font-weight:bold">this</span>;
    }
    <span style=3D"color:rgb(0,128,0);font-weight:bold">operator</span> T()=
 <span style=3D"color:rgb(0,128,0);font-weight:bold">const</span> noexcept{
        <span style=3D"color:rgb(0,128,0);font-weight:bold">return</span> v=
alue;
    }
    <span style=3D"color:rgb(176,0,64)">bool</span> is_valid() <span style=
=3D"color:rgb(0,128,0);font-weight:bold">const</span> noexcept{
        <span style=3D"color:rgb(0,128,0);font-weight:bold">return</span> v=
alue <span style=3D"color:rgb(102,102,102)">&lt;</span> max;
    }
<span style=3D"color:rgb(160,160,0)">private:</span>
    T value;
    constexpr <span style=3D"color:rgb(0,128,0);font-weight:bold">static</s=
pan> T clamp(<span style=3D"color:rgb(0,128,0);font-weight:bold">const</spa=
n> T<span style=3D"color:rgb(102,102,102)">&amp;</span> input) noexcept{
        std<span style=3D"color:rgb(102,102,102)">::</span>cout <span style=
=3D"color:rgb(102,102,102)">&lt;&lt;</span> <span style=3D"color:rgb(186,33=
,33)">&quot;VALIDATING&quot;</span> <span style=3D"color:rgb(102,102,102)">=
&lt;&lt;</span> std<span style=3D"color:rgb(102,102,102)">::</span>endl;
        <span style=3D"color:rgb(0,128,0);font-weight:bold">return</span> (=
<span style=3D"color:rgb(102,102,102)">!</span>(input <span style=3D"color:=
rgb(102,102,102)">&lt;</span> min) <span style=3D"color:rgb(102,102,102)">&=
amp;&amp;</span> input <span style=3D"color:rgb(102,102,102)">&lt;</span> m=
ax) <span style=3D"color:rgb(102,102,102)">?</span> input <span style=3D"co=
lor:rgb(102,102,102)">:</span> max;
    }
};

<span style=3D"color:rgb(0,128,0);font-weight:bold">struct</span> A
{
    bounded_type<span style=3D"color:rgb(102,102,102)">&lt;</span><span sty=
le=3D"color:rgb(176,0,64)">unsigned</span> <span style=3D"color:rgb(176,0,6=
4)">char</span>, <span style=3D"color:rgb(102,102,102)">0</span>, <span sty=
le=3D"color:rgb(102,102,102)">11&gt;</span> range_short;
    bounded_type<span style=3D"color:rgb(102,102,102)">&lt;</span><span sty=
le=3D"color:rgb(176,0,64)">unsigned</span> <span style=3D"color:rgb(176,0,6=
4)">short</span>, <span style=3D"color:rgb(102,102,102)">0</span>, <span st=
yle=3D"color:rgb(102,102,102)">1001&gt;</span> range_long;
};
<span style=3D"color:rgb(0,128,0);font-weight:bold">struct</span> B{
    bounded_type<span style=3D"color:rgb(102,102,102)">&lt;</span><span sty=
le=3D"color:rgb(176,0,64)">unsigned</span> <span style=3D"color:rgb(176,0,6=
4)">char</span>, <span style=3D"color:rgb(102,102,102)">0</span>, <span sty=
le=3D"color:rgb(102,102,102)">11&gt;</span> range_short;
};


<span style=3D"color:rgb(176,0,64)">int</span> <span style=3D"color:rgb(0,0=
,255)">main</span>()
{
    A a;
    a.range_short <span style=3D"color:rgb(102,102,102)">=3D</span> <span s=
tyle=3D"color:rgb(102,102,102)">20</span>;
    a.range_long <span style=3D"color:rgb(102,102,102)">=3D</span> <span st=
yle=3D"color:rgb(102,102,102)">9999</span>;
    std<span style=3D"color:rgb(102,102,102)">::</span>cout <span style=3D"=
color:rgb(102,102,102)">&lt;&lt;</span> <span style=3D"color:rgb(0,128,0);f=
ont-weight:bold">static_cast</span><span style=3D"color:rgb(102,102,102)">&=
lt;</span><span style=3D"color:rgb(176,0,64)">int</span><span style=3D"colo=
r:rgb(102,102,102)">&gt;</span>(a.range_short) <span style=3D"color:rgb(102=
,102,102)">&lt;&lt;</span> std<span style=3D"color:rgb(102,102,102)">::</sp=
an>endl;
    std<span style=3D"color:rgb(102,102,102)">::</span>cout <span style=3D"=
color:rgb(102,102,102)">&lt;&lt;</span> <span style=3D"color:rgb(0,128,0);f=
ont-weight:bold">static_cast</span><span style=3D"color:rgb(102,102,102)">&=
lt;</span><span style=3D"color:rgb(176,0,64)">int</span><span style=3D"colo=
r:rgb(102,102,102)">&gt;</span>(a.range_long) <span style=3D"color:rgb(102,=
102,102)">&lt;&lt;</span> std<span style=3D"color:rgb(102,102,102)">::</spa=
n>endl;
    B b;
    b.range_short <span style=3D"color:rgb(102,102,102)">=3D</span> a.range=
_short;
    <span style=3D"color:rgb(0,128,0);font-weight:bold">return</span> <span=
 style=3D"color:rgb(102,102,102)">0</span>;
}</pre></pre><br></div><div>I simply wouldn&#39;t have a getter or setter i=
n a class because I can&#39;t think of a good enough reason to do so. If I =
want something validated, I want it done within the type - and then I want =
to pass that type around anywhere I want, with each component aware that th=
e type has been validated without putting the legwork in to do it (and vali=
dation never being done more than once on each value - in the example there=
 are three bounded variables, only two &quot;VALIDATING&quot; messages).<br=
><br>Perhaps I&#39;m too invested in the strong typing mantra to see the po=
int in another approach.<br><br></div><div dir=3D"auto">But that&#39;s just=
 my preference. The down side to my approach is that it doesn&#39;t interac=
t well. A setter (i.e. an assignment) on one variable cannot check other cl=
ass variables without coupling them tightly to an owning class - if you hav=
e a set of Cartesian coordinates within the area of a circle, for example, =
X and Y cannot be set independently (though to be honest, I wouldn&#39;t wa=
nt to do that anyway). Languages with in-class getters and setters usually =
allow peeking into other class members to validate a new value.</div><div d=
ir=3D"auto"><br></div><div class=3D"gmail_quote" dir=3D"auto"><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;=
padding-left:1ex"><div dir=3D"ltr"><div>=C2=A0</div><blockquote class=3D"gm=
ail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;p=
adding-left:1ex"><div dir=3D"auto"><div dir=3D"auto"></div><div dir=3D"auto=
">The for-else is interesting. I presume</div><div dir=3D"auto"><br></div><=
div dir=3D"auto">for(init; condition; increment){</div><div dir=3D"auto">=
=C2=A0 =C2=A0 statement1;</div><div dir=3D"auto">}else{</div><div dir=3D"au=
to">=C2=A0 =C2=A0 statement2;</div><div dir=3D"auto">}</div><div dir=3D"aut=
o"><br></div><div dir=3D"auto">would be equivalent to:</div><div dir=3D"aut=
o"><br></div><div dir=3D"auto">if(init; condition){</div><div dir=3D"auto">=
=C2=A0 =C2=A0 do{</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 statement1;</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 incr=
ement;</div><div dir=3D"auto">=C2=A0 =C2=A0 } while(condition);</div><div d=
ir=3D"auto">}else{</div><div dir=3D"auto">=C2=A0 =C2=A0 statement2;</div><d=
iv dir=3D"auto">}</div><div dir=3D"auto"><br></div></div></blockquote><div>=
<br></div><div>More like:<br><br>int i;<br><div><br></div><div>for (i =3D 0=
; i &lt; 10; ++ i)</div><div>=C2=A0 =C2=A0 cout=C2=A0&lt;&lt; &quot;.&quot;=
;</div><div><br></div><div>if (i &gt;=3D 10)</div><div>=C2=A0 =C2=A0 cout=
=C2=A0&lt;&lt; &quot;Not found!&quot; &lt;&lt; endl;</div></div></div></blo=
ckquote></div><div dir=3D"auto"><br></div><div dir=3D"auto">Doh! Serves me =
right for not looking at the manual I&#39;ve been writing python for years =
- its a great language for using C++ extensions with - and I haven&#39;t se=
en that before.</div><div dir=3D"auto"><br></div><div dir=3D"auto">IMO &quo=
t;for...else...&quot; is the dumbest possible syntax for that functionality=
.. It bears no resemblance to the existing meaning of &quot;else&quot; (whic=
h is what I was going for above), especially in the context of &quot;for&qu=
ot;.</div><div dir=3D"auto"><br></div><div dir=3D"auto">I&#39;d understand =
if it were called nobreak.</div><div dir=3D"auto"><br></div><div dir=3D"aut=
o">for(...){</div><div dir=3D"auto">=C2=A0 =C2=A0 // search and break upon =
result</div><div dir=3D"auto">}nobreak{</div><div dir=3D"auto">=C2=A0 =C2=
=A0 // not found</div><div dir=3D"auto">}</div><div dir=3D"auto">// break l=
abel</div><div dir=3D"auto"><br></div><div dir=3D"auto">W<span style=3D"fon=
t-family:sans-serif">e can already get that functionality, by the way, just=
 by replacing the &quot;break&quot; keyword with &quot;return&quot; and wra=
pping it in a lambda, but thats something people either love or hate.</span=
></div><div dir=3D"auto"><br></div><div dir=3D"auto">And then we could do:<=
/div><div dir=3D"auto"><br></div><div dir=3D"auto">for(auto&amp;&amp; i : g=
et_messages()){</div><div dir=3D"auto">=C2=A0 =C2=A0 // process message</di=
v><div dir=3D"auto">}else{</div><div dir=3D"auto">=C2=A0 =C2=A0 // no messa=
ges</div><div dir=3D"auto">}</div><div dir=3D"auto"><br></div><div dir=3D"a=
uto">If anything, it serves to really confuse people who use &quot;for...el=
se...&quot; in python.</div><div class=3D"gmail_quote" dir=3D"auto"></div><=
/div>
</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/CAC%2B0CCMX%2BFKCMrnqxu_5rdyFY%2BKor8=
RSofPtpzLdRWE-xP4TNA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAC%2B0CCMX=
%2BFKCMrnqxu_5rdyFY%2BKor8RSofPtpzLdRWE-xP4TNA%40mail.gmail.com</a>.<br />

--0000000000009555e1057369043b--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 14 Aug 2018 11:46:01 -0700
Raw View
On Sunday, 12 August 2018 21:50:00 PDT Phil Bouchard wrote:
> The following example speaks for itself:
>
> for (int i = 0; i < 0; ++ i)
>     cout << ".";
> else
>     cout << "Not found!" << endl;

The following speaks for itself

  if (condition)
    for (int i = 0; i < 0; ++i)
        cout << "."
  else
    cout << "Other condition" << endl;

--
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/1547829.XK5Pz73BK2%40tjmaciei-mobl1.

.


Author: Hyman Rosen <hyman.rosen@gmail.com>
Date: Tue, 14 Aug 2018 15:34:52 -0400
Raw View
--00000000000074819805736a4ebd
Content-Type: text/plain; charset="UTF-8"

On Tue, Aug 14, 2018 at 2:46 PM Thiago Macieira <thiago@macieira.org> wrote:

> The following speaks for itself
>

But what does it say? :-)

The problem being addressed (which would need other syntax than for-else)
is that past the end of a loop, there is no a priori way of knowing whether
the
loop was exited via break or by its condition becoming false.  Keeping
track of
that requires an additional boolean variable, and some people would prefer a
syntactic construct instead.  But using a variable isn't that hard.

*bool via_break;*

*while (via_break = !!condition) { via_break = true; if (foo()) break; }if
(via_break) { } else { }*

--
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/CAHSYqdaWXW3zUYJr1Sct6KbcBkhe5igkVyvMxPXz-pqZ44HTOA%40mail.gmail.com.

--00000000000074819805736a4ebd
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue, Aug 14=
, 2018 at 2:46 PM Thiago Macieira &lt;<a href=3D"mailto:thiago@macieira.org=
" target=3D"_blank">thiago@macieira.org</a>&gt; wrote:</div><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pa=
dding-left:1ex">
The following speaks for itself<br></blockquote><div><br>But what does it s=
ay? :-)<br><br>The problem being addressed (which would need other syntax t=
han for-else)<br>is that past the end of a loop, there is no a priori way o=
f knowing whether the<br>loop was exited via break or by its condition beco=
ming false.=C2=A0 Keeping track of<br>that requires an additional boolean v=
ariable, and some people would prefer a<br>syntactic construct instead.=C2=
=A0 But using a variable isn&#39;t that hard.<br><br><font face=3D"monospac=
e, monospace"><b>bool via_break;</b></font></div><div><font face=3D"monospa=
ce, monospace"><b>while (via_break =3D !!condition) { via_break =3D true; i=
f (foo()) break; }<br>if (via_break) { } else { }</b></font><br></div></div=
></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/CAHSYqdaWXW3zUYJr1Sct6KbcBkhe5igkVyvM=
xPXz-pqZ44HTOA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAHSYqdaWXW3zUYJr=
1Sct6KbcBkhe5igkVyvMxPXz-pqZ44HTOA%40mail.gmail.com</a>.<br />

--00000000000074819805736a4ebd--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 14 Aug 2018 12:39:40 -0700
Raw View
On Tuesday, 14 August 2018 12:34:52 PDT Hyman Rosen wrote:
> > The following speaks for itself
>
> But what does it say?
>
> The problem being addressed (which would need other syntax than for-else)

That this syntax is already in use :-)

--
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/21031030.hIcliWo2kD%40tjmaciei-mobl1.

.


Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Tue, 14 Aug 2018 16:54:54 -0400
Raw View
On 2018-08-14 15:34, Hyman Rosen wrote:
> The problem being addressed (which would need other syntax than for-else)
> is that past the end of a loop, there is no a priori way of knowing whether
> the loop was exited via break or by its condition becoming false.

Someone has to say it:

  for (auto i : some_container)
  {
    if (test(i))
      goto end_of_loop; // break
  }
  // else
  handle_not_found()
  end_of_loop:

--
Matthew

--
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/48b93935-0710-9f4b-180f-7957df2db3f5%40gmail.com.

.


Author: Phil Bouchard <philippeb8@gmail.com>
Date: Tue, 14 Aug 2018 18:30:39 -0700 (PDT)
Raw View
------=_Part_2212_737273385.1534296639764
Content-Type: multipart/alternative;
 boundary="----=_Part_2213_636240359.1534296639765"

------=_Part_2213_636240359.1534296639765
Content-Type: text/plain; charset="UTF-8"



On Tuesday, August 14, 2018 at 2:02:51 PM UTC-4, Jake Arkinstall wrote:
>
> On Tue, 14 Aug 2018, 01:58 Phil Bouchard, <phili...@gmail.com
> <javascript:>> wrote:
>
>> Ah you mean like the example attached. I agree it is even cleaner this
>> way!
>>
>
> Not quite. I'd have a type that guarantees that the value won't be
> malformed, or provides an easy way of checking.
>
> #include <iostream>
> template<typename T, T min, T max> // template<LessThanComparable T,...> in C++20struct bounded_type{
>     constexpr bounded_type() noexcept
>     :
>         value{max}
>     {}
>     constexpr bounded_type(const T& raw) noexcept
>     :
>         value{clamp(raw)}
>     {}
>     constexpr bounded_type& operator=(const T& raw) noexcept{
>         value = clamp(raw);
>         return *this;
>     }
>     operator T() const noexcept{
>         return value;
>     }
>     bool is_valid() const noexcept{
>         return value < max;
>     }private:
>     T value;
>     constexpr static T clamp(const T& input) noexcept{
>         std::cout << "VALIDATING" << std::endl;
>         return (!(input < min) && input < max) ? input : max;
>     }
> };
> struct A
> {
>     bounded_type<unsigned char, 0, 11> range_short;
>     bounded_type<unsigned short, 0, 1001> range_long;
> };struct B{
>     bounded_type<unsigned char, 0, 11> range_short;
> };
>
> int main()
> {
>     A a;
>     a.range_short = 20;
>     a.range_long = 9999;
>     std::cout << static_cast<int>(a.range_short) << std::endl;
>     std::cout << static_cast<int>(a.range_long) << std::endl;
>     B b;
>     b.range_short = a.range_short;
>     return 0;
> }
>
>
> I simply wouldn't have a getter or setter in a class because I can't think
> of a good enough reason to do so. If I want something validated, I want it
> done within the type - and then I want to pass that type around anywhere I
> want, with each component aware that the type has been validated without
> putting the legwork in to do it (and validation never being done more than
> once on each value - in the example there are three bounded variables, only
> two "VALIDATING" messages).
>
> Perhaps I'm too invested in the strong typing mantra to see the point in
> another approach.
>
> But that's just my preference. The down side to my approach is that it
> doesn't interact well. A setter (i.e. an assignment) on one variable cannot
> check other class variables without coupling them tightly to an owning
> class - if you have a set of Cartesian coordinates within the area of a
> circle, for example, X and Y cannot be set independently (though to be
> honest, I wouldn't want to do that anyway). Languages with in-class getters
> and setters usually allow peeking into other class members to validate a
> new value.
>

Thanks for sharing your perspective, it is very objective! My approach
takes fewer lines of code whereas yours is strongly typed. I guess it
depends on the context whether mine or yours is better (I'm not a big fan
of nested classes either because we can't specialize them easily for other
purposes).


>
>>
>>> The for-else is interesting. I presume
>>>
>>> for(init; condition; increment){
>>>     statement1;
>>> }else{
>>>     statement2;
>>> }
>>>
>>> would be equivalent to:
>>>
>>> if(init; condition){
>>>     do{
>>>           statement1;
>>>           increment;
>>>     } while(condition);
>>> }else{
>>>     statement2;
>>> }
>>>
>>>
>> More like:
>>
>> int i;
>>
>> for (i = 0; i < 10; ++ i)
>>     cout << ".";
>>
>> if (i >= 10)
>>     cout << "Not found!" << endl;
>>
>
> Doh! Serves me right for not looking at the manual I've been writing
> python for years - its a great language for using C++ extensions with - and
> I haven't seen that before.
>

Yeah, Python is more popular than C / C++ (and can be compiled using
"Cython" as well):
https://spectrum.ieee.org/static/interactive-the-top-programming-languages-2018


> IMO "for...else..." is the dumbest possible syntax for that functionality.
> It bears no resemblance to the existing meaning of "else" (which is what I
> was going for above), especially in the context of "for".
>

You're right and I forgot that it may confuse nested if statements as well.


> I'd understand if it were called nobreak.
> for(...){
>     // search and break upon result
> }nobreak{
>     // not found
> }
> // break label
>
> We can already get that functionality, by the way, just by replacing the
> "break" keyword with "return" and wrapping it in a lambda, but thats
> something people either love or hate.
>
> And then we could do:
>
> for(auto&& i : get_messages()){
>     // process message
> }else{
>     // no messages
> }
>
> If anything, it serves to really confuse people who use "for...else..." in
> python.
>

Indeed, you're right. And not to mention Python is stuck with "if...
elif... else" (and a garbage collector draining all the memory).

--
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/4201addd-3a9e-4936-b662-bf404b62c92b%40isocpp.org.

------=_Part_2213_636240359.1534296639765
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Tuesday, August 14, 2018 at 2:02:51 PM UTC-4, J=
ake Arkinstall wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><div dir=3D"auto"><div class=3D"gmail_quote" dir=3D"auto"><div dir=
=3D"ltr">On Tue, 14 Aug 2018, 01:58 Phil Bouchard, &lt;<a href=3D"javascrip=
t:" rel=3D"nofollow" target=3D"_blank" gdf-obfuscated-mailto=3D"BKFcgmKJDgA=
J" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return true;" onclick=
=3D"this.href=3D&#39;javascript:&#39;;return true;">phili...@gmail.com</a>&=
gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Ah you =
mean like the example attached. I agree it is even cleaner this way!</div><=
/blockquote></div><div dir=3D"auto"><br></div><div>Not quite. I&#39;d have =
a type that guarantees that the value won&#39;t be malformed, or provides a=
n easy way of checking.<br><br><pre style=3D"margin:0px;line-height:125%"><=
pre style=3D"margin:0px;line-height:125%"><span style=3D"color:rgb(188,122,=
0)">#include &lt;iostream&gt;</span>

<span style=3D"color:rgb(0,128,0);font-weight:bold">template</span><span st=
yle=3D"color:rgb(102,102,102)">&lt;</span><span style=3D"color:rgb(0,128,0)=
;font-weight:bold">typename</span> T, T min, T max<span style=3D"color:rgb(=
102,102,102)">&gt;</span> // template&lt;LessThanComparable T,...&gt; in C+=
+20
<span style=3D"color:rgb(0,128,0);font-weight:bold">struct</span> bounded_t=
ype{
    constexpr bounded_type() noexcept
    <span style=3D"color:rgb(102,102,102)">:</span>
        value{max}
    {}
    constexpr bounded_type(<span style=3D"color:rgb(0,128,0);font-weight:bo=
ld">const</span> T<span style=3D"color:rgb(102,102,102)">&amp;</span> raw) =
noexcept
    <span style=3D"color:rgb(102,102,102)">:</span>
        value{clamp(raw)}
    {}
    constexpr bounded_type<span style=3D"color:rgb(102,102,102)">&amp;</spa=
n> <span style=3D"color:rgb(0,128,0);font-weight:bold">operator</span><span=
 style=3D"color:rgb(102,102,102)">=3D</span>(<span style=3D"color:rgb(0,128=
,0);font-weight:bold">const</span> T<span style=3D"color:rgb(102,102,102)">=
&amp;</span> raw) noexcept{
        value <span style=3D"color:rgb(102,102,102)">=3D</span> clamp(raw);
        <span style=3D"color:rgb(0,128,0);font-weight:bold">return</span> <=
span style=3D"color:rgb(102,102,102)">*</span><span style=3D"color:rgb(0,12=
8,0);font-weight:bold">this</span>;
    }
    <span style=3D"color:rgb(0,128,0);font-weight:bold">operator</span> T()=
 <span style=3D"color:rgb(0,128,0);font-weight:bold">const</span> noexcept{
        <span style=3D"color:rgb(0,128,0);font-weight:bold">return</span> v=
alue;
    }
    <span style=3D"color:rgb(176,0,64)">bool</span> is_valid() <span style=
=3D"color:rgb(0,128,0);font-weight:bold">const</span> noexcept{
        <span style=3D"color:rgb(0,128,0);font-weight:bold">return</span> v=
alue <span style=3D"color:rgb(102,102,102)">&lt;</span> max;
    }
<span style=3D"color:rgb(160,160,0)">private:</span>
    T value;
    constexpr <span style=3D"color:rgb(0,128,0);font-weight:bold">static</s=
pan> T clamp(<span style=3D"color:rgb(0,128,0);font-weight:bold">const</spa=
n> T<span style=3D"color:rgb(102,102,102)">&amp;</span> input) noexcept{
        std<span style=3D"color:rgb(102,102,102)">::</span>cout <span style=
=3D"color:rgb(102,102,102)">&lt;&lt;</span> <span style=3D"color:rgb(186,33=
,33)">&quot;VALIDATING&quot;</span> <span style=3D"color:rgb(102,102,102)">=
&lt;&lt;</span> std<span style=3D"color:rgb(102,102,102)">::</span>endl;
        <span style=3D"color:rgb(0,128,0);font-weight:bold">return</span> (=
<span style=3D"color:rgb(102,102,102)">!</span>(input <span style=3D"color:=
rgb(102,102,102)">&lt;</span> min) <span style=3D"color:rgb(102,102,102)">&=
amp;&amp;</span> input <span style=3D"color:rgb(102,102,102)">&lt;</span> m=
ax) <span style=3D"color:rgb(102,102,102)">?</span> input <span style=3D"co=
lor:rgb(102,102,102)">:</span> max;
    }
};

<span style=3D"color:rgb(0,128,0);font-weight:bold">struct</span> A
{
    bounded_type<span style=3D"color:rgb(102,102,102)">&lt;</span><span sty=
le=3D"color:rgb(176,0,64)">unsigned</span> <span style=3D"color:rgb(176,0,6=
4)">char</span>, <span style=3D"color:rgb(102,102,102)">0</span>, <span sty=
le=3D"color:rgb(102,102,102)">11&gt;</span> range_short;
    bounded_type<span style=3D"color:rgb(102,102,102)">&lt;</span><span sty=
le=3D"color:rgb(176,0,64)">unsigned</span> <span style=3D"color:rgb(176,0,6=
4)">short</span>, <span style=3D"color:rgb(102,102,102)">0</span>, <span st=
yle=3D"color:rgb(102,102,102)">1001&gt;</span> range_long;
};
<span style=3D"color:rgb(0,128,0);font-weight:bold">struct</span> B{
    bounded_type<span style=3D"color:rgb(102,102,102)">&lt;</span><span sty=
le=3D"color:rgb(176,0,64)">unsigned</span> <span style=3D"color:rgb(176,0,6=
4)">char</span>, <span style=3D"color:rgb(102,102,102)">0</span>, <span sty=
le=3D"color:rgb(102,102,102)">11&gt;</span> range_short;
};


<span style=3D"color:rgb(176,0,64)">int</span> <span style=3D"color:rgb(0,0=
,255)">main</span>()
{
    A a;
    a.range_short <span style=3D"color:rgb(102,102,102)">=3D</span> <span s=
tyle=3D"color:rgb(102,102,102)">20</span>;
    a.range_long <span style=3D"color:rgb(102,102,102)">=3D</span> <span st=
yle=3D"color:rgb(102,102,102)">9999</span>;
    std<span style=3D"color:rgb(102,102,102)">::</span>cout <span style=3D"=
color:rgb(102,102,102)">&lt;&lt;</span> <span style=3D"color:rgb(0,128,0);f=
ont-weight:bold">static_cast</span><span style=3D"color:rgb(102,102,102)">&=
lt;</span><span style=3D"color:rgb(176,0,64)">int</span><span style=3D"colo=
r:rgb(102,102,102)">&gt;</span>(a.range_<wbr>short) <span style=3D"color:rg=
b(102,102,102)">&lt;&lt;</span> std<span style=3D"color:rgb(102,102,102)">:=
:</span>endl;
    std<span style=3D"color:rgb(102,102,102)">::</span>cout <span style=3D"=
color:rgb(102,102,102)">&lt;&lt;</span> <span style=3D"color:rgb(0,128,0);f=
ont-weight:bold">static_cast</span><span style=3D"color:rgb(102,102,102)">&=
lt;</span><span style=3D"color:rgb(176,0,64)">int</span><span style=3D"colo=
r:rgb(102,102,102)">&gt;</span>(a.range_long) <span style=3D"color:rgb(102,=
102,102)">&lt;&lt;</span> std<span style=3D"color:rgb(102,102,102)">::</spa=
n>endl;
    B b;
    b.range_short <span style=3D"color:rgb(102,102,102)">=3D</span> a.range=
_short;
    <span style=3D"color:rgb(0,128,0);font-weight:bold">return</span> <span=
 style=3D"color:rgb(102,102,102)">0</span>;
}</pre></pre><br></div><div>I simply wouldn&#39;t have a getter or setter i=
n a class because I can&#39;t think of a good enough reason to do so. If I =
want something validated, I want it done within the type - and then I want =
to pass that type around anywhere I want, with each component aware that th=
e type has been validated without putting the legwork in to do it (and vali=
dation never being done more than once on each value - in the example there=
 are three bounded variables, only two &quot;VALIDATING&quot; messages).<br=
><br>Perhaps I&#39;m too invested in the strong typing mantra to see the po=
int in another approach.<br><br></div><div dir=3D"auto">But that&#39;s just=
 my preference. The down side to my approach is that it doesn&#39;t interac=
t well. A setter (i.e. an assignment) on one variable cannot check other cl=
ass variables without coupling them tightly to an owning class - if you hav=
e a set of Cartesian coordinates within the area of a circle, for example, =
X and Y cannot be set independently (though to be honest, I wouldn&#39;t wa=
nt to do that anyway). Languages with in-class getters and setters usually =
allow peeking into other class members to validate a new value.</div></div>=
</div></blockquote><div><br></div><div>Thanks for sharing your perspective,=
 it is very objective! My approach takes fewer lines of code whereas yours =
is strongly typed. I guess it depends on the context whether mine or yours =
is better (I&#39;m not a big fan of nested classes either because we can&#3=
9;t specialize them easily for other purposes).</div><div><br></div><blockq=
uote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-lef=
t: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div dir=3D"auto"><d=
iv dir=3D"auto"><br></div><div class=3D"gmail_quote" dir=3D"auto"><blockquo=
te class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc so=
lid;padding-left:1ex"><div dir=3D"ltr"><div>=C2=A0</div><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"auto"><div dir=3D"auto"></div><div dir=
=3D"auto">The for-else is interesting. I presume</div><div dir=3D"auto"><br=
></div><div dir=3D"auto">for(init; condition; increment){</div><div dir=3D"=
auto">=C2=A0 =C2=A0 statement1;</div><div dir=3D"auto">}else{</div><div dir=
=3D"auto">=C2=A0 =C2=A0 statement2;</div><div dir=3D"auto">}</div><div dir=
=3D"auto"><br></div><div dir=3D"auto">would be equivalent to:</div><div dir=
=3D"auto"><br></div><div dir=3D"auto">if(init; condition){</div><div dir=3D=
"auto">=C2=A0 =C2=A0 do{</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 statement1;</div><div dir=3D"auto">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 increment;</div><div dir=3D"auto">=C2=A0 =C2=A0 } while(condition);</di=
v><div dir=3D"auto">}else{</div><div dir=3D"auto">=C2=A0 =C2=A0 statement2;=
</div><div dir=3D"auto">}</div><div dir=3D"auto"><br></div></div></blockquo=
te><div><br></div><div>More like:<br><br>int i;<br><div><br></div><div>for =
(i =3D 0; i &lt; 10; ++ i)</div><div>=C2=A0 =C2=A0 cout=C2=A0&lt;&lt; &quot=
;.&quot;;</div><div><br></div><div>if (i &gt;=3D 10)</div><div>=C2=A0 =C2=
=A0 cout=C2=A0&lt;&lt; &quot;Not found!&quot; &lt;&lt; endl;</div></div></d=
iv></blockquote></div><div dir=3D"auto"><br></div><div dir=3D"auto">Doh! Se=
rves me right for not looking at the manual I&#39;ve been writing python fo=
r years - its a great language for using C++ extensions with - and I haven&=
#39;t seen that before.<br></div><div dir=3D"auto"></div></div></div></bloc=
kquote><div><br></div><div>Yeah, Python is more popular than C / C++ (and c=
an be compiled using &quot;Cython&quot;=C2=A0as well):</div><div>https://sp=
ectrum.ieee.org/static/interactive-the-top-programming-languages-2018<br></=
div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><div dir=3D"auto"><div dir=3D"auto">IMO &quot;for...else...&quot; =
is the dumbest possible syntax for that functionality. It bears no resembla=
nce to the existing meaning of &quot;else&quot; (which is what I was going =
for above), especially in the context of &quot;for&quot;.</div><div dir=3D"=
auto"></div></div></div></blockquote><div><br></div><div>You&#39;re right a=
nd I forgot that it may confuse nested if statements as well.</div><div>=C2=
=A0</div><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"><div=
 dir=3D"auto"><div dir=3D"auto">I&#39;d understand if it were called nobrea=
k.<br></div><div dir=3D"auto">for(...){</div><div dir=3D"auto">=C2=A0 =C2=
=A0 // search and break upon result</div><div dir=3D"auto">}nobreak{</div><=
div dir=3D"auto">=C2=A0 =C2=A0 // not found</div><div dir=3D"auto">}</div><=
div dir=3D"auto">// break label</div><div dir=3D"auto"><br></div><div dir=
=3D"auto">W<span style=3D"font-family:sans-serif">e can already get that fu=
nctionality, by the way, just by replacing the &quot;break&quot; keyword wi=
th &quot;return&quot; and wrapping it in a lambda, but thats something peop=
le either love or hate.</span></div><div dir=3D"auto"><br></div><div dir=3D=
"auto">And then we could do:</div><div dir=3D"auto"><br></div><div dir=3D"a=
uto">for(auto&amp;&amp; i : get_messages()){</div><div dir=3D"auto">=C2=A0 =
=C2=A0 // process message</div><div dir=3D"auto">}else{</div><div dir=3D"au=
to">=C2=A0 =C2=A0 // no messages</div><div dir=3D"auto">}</div><div dir=3D"=
auto"><br></div><div dir=3D"auto">If anything, it serves to really confuse =
people who use &quot;for...else...&quot; in python.</div></div></div></bloc=
kquote><div><br></div><div>Indeed, you&#39;re right. And not to mention Pyt=
hon is stuck with &quot;if... elif... else&quot; (and a garbage collector d=
raining all the memory).</div></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/4201addd-3a9e-4936-b662-bf404b62c92b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4201addd-3a9e-4936-b662-bf404b62c92b=
%40isocpp.org</a>.<br />

------=_Part_2213_636240359.1534296639765--

------=_Part_2212_737273385.1534296639764--

.


Author: Phil Bouchard <philippeb8@gmail.com>
Date: Tue, 14 Aug 2018 18:34:19 -0700 (PDT)
Raw View
------=_Part_2162_89876551.1534296859572
Content-Type: multipart/alternative;
 boundary="----=_Part_2163_861106715.1534296859572"

------=_Part_2163_861106715.1534296859572
Content-Type: text/plain; charset="UTF-8"



On Tuesday, August 14, 2018 at 1:10:21 PM UTC-4, Barry Revzin wrote:
>
>
>
> On Tuesday, August 14, 2018 at 4:16:53 AM UTC-5, Tony V E wrote:
>>
>> No,IIUC,  the for-else typically (ie python) enters the else if the for
>> loop reaches the end.
>> It seems odd, but the idea is:
>>
>> for (auto strand : haystack)
>> {
>>    if (strand == needle)
>>         found_it(strand);
>> }
>> else
>>    not_found();
>>
>> I think there has already been a proposal for this. Not sure what
>> happened. Most likely "we need another flow control like we need another
>> hole in our heads".
>>
>
> A problem with for/else is that this code (intentionally unformatted):
>
> if (...)
> for (...)
> s1;
> else
> s2;
>
> changes from the else being attached to the outer if (the only thing it
> could be attached to today) to being attached to the inner for (which is
> now closer).
>

You're absolutely right!

--
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/31e168ba-e730-44fd-86ed-3c654d19669f%40isocpp.org.

------=_Part_2163_861106715.1534296859572
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Tuesday, August 14, 2018 at 1:10:21 PM UTC-4, B=
arry Revzin wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
ltr"><br><br>On Tuesday, August 14, 2018 at 4:16:53 AM UTC-5, Tony V E wrot=
e:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bor=
der-left:1px #ccc solid;padding-left:1ex"><div lang=3D"en-US" style=3D"back=
ground-color:rgb(255,255,255);line-height:initial">                        =
                                                              <div style=3D=
"width:100%;font-size:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-=
serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-color:r=
gb(255,255,255)">No,IIUC, =C2=A0the for-else typically (ie python) enters t=
he else if the for loop reaches the end.</div><div style=3D"width:100%;font=
-size:initial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif=
;color:rgb(31,73,125);text-align:initial;background-color:rgb(255,255,255)"=
>It seems odd, but the idea is:</div><div style=3D"width:100%;font-size:ini=
tial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rg=
b(31,73,125);text-align:initial;background-color:rgb(255,255,255)"><br></di=
v><div style=3D"width:100%;font-size:initial;font-family:Calibri,&#39;Slate=
 Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;bac=
kground-color:rgb(255,255,255)">for (auto strand : haystack)</div><div styl=
e=3D"width:100%;font-size:initial;font-family:Calibri,&#39;Slate Pro&#39;,s=
ans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-col=
or:rgb(255,255,255)">{</div><div style=3D"width:100%;font-size:initial;font=
-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,1=
25);text-align:initial;background-color:rgb(255,255,255)">=C2=A0 =C2=A0if (=
strand =3D=3D needle)</div><div style=3D"width:100%;font-size:initial;font-=
family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,12=
5);text-align:initial;background-color:rgb(255,255,255)">=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 found_it(strand);</div><div style=3D"width:100%;font-size:initia=
l;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(3=
1,73,125);text-align:initial;background-color:rgb(255,255,255)">}</div><div=
 style=3D"width:100%;font-size:initial;font-family:Calibri,&#39;Slate Pro&#=
39;,sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;backgroun=
d-color:rgb(255,255,255)">else</div><div style=3D"width:100%;font-size:init=
ial;font-family:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb=
(31,73,125);text-align:initial;background-color:rgb(255,255,255)">=C2=A0 =
=C2=A0not_found();</div><div style=3D"width:100%;font-size:initial;font-fam=
ily:Calibri,&#39;Slate Pro&#39;,sans-serif,sans-serif;color:rgb(31,73,125);=
text-align:initial;background-color:rgb(255,255,255)"><br></div><div style=
=3D"width:100%;font-size:initial;font-family:Calibri,&#39;Slate Pro&#39;,sa=
ns-serif,sans-serif;color:rgb(31,73,125);text-align:initial;background-colo=
r:rgb(255,255,255)">I think there has already been a proposal for this. Not=
 sure what happened. Most likely &quot;we need another flow control like we=
 need another hole in our heads&quot;.</div></div></blockquote><div><br></d=
iv><div>A problem with for/else is that this code (intentionally unformatte=
d):</div><div><br></div><div><div style=3D"background-color:rgb(250,250,250=
);border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wr=
ap:break-word"><code><div><span style=3D"color:#008">if</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">(</span><font color=3D"#=
000000"><span style=3D"color:#660">...</span></font><span style=3D"color:#6=
60">)</span><span style=3D"color:#000"><br></span><span style=3D"color:#008=
">for</span><span style=3D"color:#000"> </span><span style=3D"color:#660">(=
....)</span><span style=3D"color:#000"><br>s1</span><span style=3D"color:#66=
0">;</span><span style=3D"color:#000"><br></span><span style=3D"color:#008"=
>else</span><span style=3D"color:#000"><br>s2</span><span style=3D"color:#6=
60">;</span></div></code></div><br>changes from the else being attached to =
the outer if (the only thing it could be attached to today) to being attach=
ed to the inner for (which is now closer).=C2=A0<br></div></div></blockquot=
e><div><br></div><div>You&#39;re absolutely right!=C2=A0</div></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/31e168ba-e730-44fd-86ed-3c654d19669f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/31e168ba-e730-44fd-86ed-3c654d19669f=
%40isocpp.org</a>.<br />

------=_Part_2163_861106715.1534296859572--

------=_Part_2162_89876551.1534296859572--

.


Author: Richard Hodges <hodges.r@gmail.com>
Date: Wed, 15 Aug 2018 09:21:41 +0200
Raw View
--0000000000004309ef0573742ef2
Content-Type: text/plain; charset="UTF-8"

On Tue, 14 Aug 2018 at 22:54, Matthew Woehlke <mwoehlke.floss@gmail.com>
wrote:

> On 2018-08-14 15:34, Hyman Rosen wrote:
> > The problem being addressed (which would need other syntax than for-else)
> > is that past the end of a loop, there is no a priori way of knowing
> whether
> > the loop was exited via break or by its condition becoming false.
>
> Someone has to say it:
>

Very well said. We already have the feature in a more flexible package. It
also breaks out of nested loops with perfect object destruction.


>
>   for (auto i : some_container)
>   {
>     if (test(i))
>       goto end_of_loop; // break
>   }
>   // else
>   handle_not_found()
>   end_of_loop:
>
> --
> Matthew
>
> --
> 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/48b93935-0710-9f4b-180f-7957df2db3f5%40gmail.com
> .
>

--
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/CALvx3hZHpAk1uQ7SjTqDZALzQ0cbYsU_cRuZ3WxpCMB2MyQ3RA%40mail.gmail.com.

--0000000000004309ef0573742ef2
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue=
, 14 Aug 2018 at 22:54, Matthew Woehlke &lt;<a href=3D"mailto:mwoehlke.flos=
s@gmail.com">mwoehlke.floss@gmail.com</a>&gt; wrote:<br></div><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;=
padding-left:1ex">On 2018-08-14 15:34, Hyman Rosen wrote:<br>
&gt; The problem being addressed (which would need other syntax than for-el=
se)<br>
&gt; is that past the end of a loop, there is no a priori way of knowing wh=
ether<br>
&gt; the loop was exited via break or by its condition becoming false.<br>
<br>
Someone has to say it:<br></blockquote><div><br></div><div>Very well said. =
We already have the feature in a more flexible package. It also breaks out =
of nested loops with perfect object destruction.</div><div>=C2=A0</div><blo=
ckquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #c=
cc solid;padding-left:1ex">
<br>
=C2=A0 for (auto i : some_container)<br>
=C2=A0 {<br>
=C2=A0 =C2=A0 if (test(i))<br>
=C2=A0 =C2=A0 =C2=A0 goto end_of_loop; // break<br>
=C2=A0 }<br>
=C2=A0 // else<br>
=C2=A0 handle_not_found()<br>
=C2=A0 end_of_loop:<br>
<br>
-- <br>
Matthew<br>
<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 <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/48b93935-0710-9f4b-180f-7957df2db3f5%=
40gmail.com" rel=3D"noreferrer" target=3D"_blank">https://groups.google.com=
/a/isocpp.org/d/msgid/std-proposals/48b93935-0710-9f4b-180f-7957df2db3f5%40=
gmail.com</a>.<br>
</blockquote></div></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/CALvx3hZHpAk1uQ7SjTqDZALzQ0cbYsU_cRuZ=
3WxpCMB2MyQ3RA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALvx3hZHpAk1uQ7S=
jTqDZALzQ0cbYsU_cRuZ3WxpCMB2MyQ3RA%40mail.gmail.com</a>.<br />

--0000000000004309ef0573742ef2--

.


Author: Vnat Vagner <vnataneg.jykhan@gmail.com>
Date: Tue, 21 Aug 2018 16:33:13 -0700 (PDT)
Raw View
------=_Part_2177_1784103262.1534894393988
Content-Type: multipart/alternative;
 boundary="----=_Part_2178_381426449.1534894393988"

------=_Part_2178_381426449.1534894393988
Content-Type: text/plain; charset="UTF-8"

Perhaps this alternative:

for( auto e : cont) {
   ...
}
case broken {}
case done {}

would avoid ambiguity?

--
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/0d9a0443-ccd3-4a90-b7a7-852f090384d6%40isocpp.org.

------=_Part_2178_381426449.1534894393988
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Perhaps this alternative:</div><div><br></div>for( au=
to e : cont) {<div>=C2=A0 =C2=A0...</div><div>}</div><div>case broken {}</d=
iv><div>case done {}</div><div><br></div><div>would avoid ambiguity?</div><=
/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/0d9a0443-ccd3-4a90-b7a7-852f090384d6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0d9a0443-ccd3-4a90-b7a7-852f090384d6=
%40isocpp.org</a>.<br />

------=_Part_2178_381426449.1534894393988--

------=_Part_2177_1784103262.1534894393988--

.