Topic: const iterator inside loop


Author: Arthur Tchaikovsky <atch.cpp@gmail.com>
Date: Thu, 3 Sep 2015 08:07:24 -0700 (PDT)
Raw View
------=_Part_346_1074837870.1441292844007
Content-Type: multipart/alternative;
 boundary="----=_Part_347_1182834167.1441292844007"

------=_Part_347_1182834167.1441292844007
Content-Type: text/plain; charset=UTF-8

Hi guys,
I very often come across a situation where I need to declare two iterators
inside a loop, namely beg and end of some container and I want only the beg
iterator to be able to change position, but the end iterator to be let's
say const. At this moment AFAIK the workaround for it would be:

const auto end = cont.cend();
for (auto beg = cont.cbegin(); beg != end; ++beg)
{
/*here inside this loop I only ever need to be able to move beg iterator
but I want to make sure that end iterator is never moved from initial
position*/
}

The above approach has few issues namely introducing end into the scope
where it logically doesn't belong. I could of course introduce another
scope but this seem like unnatural solution for a simple problem.
I'd like to be able to write:

for (auto beg = cont.cbegin(), const end = cont.cend(); beg != end; ++beg)
{
/*Here the end iterator is of this same type as beg but it is also made
const so there is no possibility of me accidentally move this iterator*/
}

Any thoughts?


--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<div dir=3D"ltr">Hi guys, <br>I very often come across a situation where I =
need to declare two iterators inside a loop, namely beg and end of some con=
tainer and I want only the beg iterator to be able to change position, but =
the end iterator to be let&#39;s say const. At this moment AFAIK the workar=
ound for it would be:<br><br>const auto end =3D cont.cend();<br>for (auto b=
eg =3D cont.cbegin(); beg !=3D end; ++beg)<br>{<br>/*here inside this loop =
I only ever need to be able to move beg iterator but I want to make sure th=
at end iterator is never moved from initial position*/<br>}<br><br>The abov=
e approach has few issues namely introducing end into the scope where it lo=
gically doesn&#39;t belong. I could of course introduce another scope but t=
his seem like unnatural solution for a simple problem.<br>I&#39;d like to b=
e able to write:<br><br>for (auto beg =3D cont.cbegin(), const end =3D cont=
..cend(); beg !=3D end; ++beg)<br>{<br>/*Here the end iterator is of this sa=
me type as beg but it is also made const so there is no possibility of me a=
ccidentally move this iterator*/<br>}<br><br>Any thoughts?<br><br><br></div=
>

<p></p>

-- <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+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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_347_1182834167.1441292844007--
------=_Part_346_1074837870.1441292844007--

.


Author: =?UTF-8?Q?Klaim_=2D_Jo=C3=ABl_Lamotte?= <mjklaim@gmail.com>
Date: Fri, 4 Sep 2015 03:49:11 +0200
Raw View
--001a11c25d923c6582051ee21bff
Content-Type: text/plain; charset=UTF-8

On 3 September 2015 at 17:07, Arthur Tchaikovsky <atch.cpp@gmail.com> wrote:

> Hi guys,
> I very often come across a situation where I need to declare two iterators
> inside a loop, namely beg and end of some container and I want only the beg
> iterator to be able to change position, but the end iterator to be let's
> say const. At this moment AFAIK the workaround for it would be:
>
> const auto end = cont.cend();
> for (auto beg = cont.cbegin(); beg != end; ++beg)
> {
> /*here inside this loop I only ever need to be able to move beg iterator
> but I want to make sure that end iterator is never moved from initial
> position*/
> }
>
> The above approach has few issues namely introducing end into the scope
> where it logically doesn't belong. I could of course introduce another
> scope but this seem like unnatural solution for a simple problem.
> I'd like to be able to write:
>
> for (auto beg = cont.cbegin(), const end = cont.cend(); beg != end; ++beg)
> {
> /*Here the end iterator is of this same type as beg but it is also made
> const so there is no possibility of me accidentally move this iterator*/
> }
>
> Any thoughts?
>
>

I instinctively thought that this could work but apparently (gcc tells me)
it does not:

    for (auto beg = cont.cbegin(), const auto end = cont.cend(); beg !=
end; ++beg)

I'm assuming here that you really need access to the iterators so
for-range-loop and for_each are not a solution?

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

--001a11c25d923c6582051ee21bff
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo=
te">On 3 September 2015 at 17:07, Arthur Tchaikovsky <span dir=3D"ltr">&lt;=
<a href=3D"mailto:atch.cpp@gmail.com" target=3D"_blank">atch.cpp@gmail.com<=
/a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:=
0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);=
border-left-style:solid;padding-left:1ex"><div dir=3D"ltr">Hi guys, <br>I v=
ery often come across a situation where I need to declare two iterators ins=
ide a loop, namely beg and end of some container and I want only the beg it=
erator to be able to change position, but the end iterator to be let&#39;s =
say const. At this moment AFAIK the workaround for it would be:<br><br>cons=
t auto end =3D cont.cend();<br>for (auto beg =3D cont.cbegin(); beg !=3D en=
d; ++beg)<br>{<br>/*here inside this loop I only ever need to be able to mo=
ve beg iterator but I want to make sure that end iterator is never moved fr=
om initial position*/<br>}<br><br>The above approach has few issues namely =
introducing end into the scope where it logically doesn&#39;t belong. I cou=
ld of course introduce another scope but this seem like unnatural solution =
for a simple problem.<br>I&#39;d like to be able to write:<br><br>for (auto=
 beg =3D cont.cbegin(), const end =3D cont.cend(); beg !=3D end; ++beg)<br>=
{<br>/*Here the end iterator is of this same type as beg but it is also mad=
e const so there is no possibility of me accidentally move this iterator*/<=
br>}<br><br></div></blockquote><blockquote class=3D"gmail_quote" style=3D"m=
argin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204=
,204);border-left-style:solid;padding-left:1ex"><div dir=3D"ltr">Any though=
ts?<span class=3D""><font color=3D"#888888"><br>=C2=A0<br></font></span></d=
iv></blockquote><div><br></div><div>I instinctively thought that this could=
 work but apparently (gcc tells me) it does not:</div><div><br></div><div>=
=C2=A0 =C2=A0 for (auto beg =3D cont.cbegin(), const auto end =3D cont.cend=
(); beg !=3D end; ++beg)<br></div><div><br></div><div>I&#39;m assuming here=
 that you really need access to the iterators so for-range-loop and for_eac=
h are not a solution?</div><div><br></div><div><br></div><div><br></div></d=
iv></div></div>

<p></p>

-- <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+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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a11c25d923c6582051ee21bff--

.


Author: David Krauss <potswa@gmail.com>
Date: Fri, 4 Sep 2015 10:07:58 +0800
Raw View
--Apple-Mail=_A71B7D2C-FC48-43E5-A9D1-0A8E9795CAF1
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9309=E2=80=9303, at 11:07 PM, Arthur Tchaikovsky <atch.cpp@=
gmail.com> wrote:
>=20
> Any thoughts?

The Ranges TS will solve this. It models just such a half-const iterator pa=
ir.

In the meantime, you can do this:

for (auto beg =3D cont.cbegin(), end_var =3D cont.cend(); beg !=3D end; ++b=
eg) {
    auto const & end =3D end_var;

Or, if end is literally initialized by cont.cend(), don=E2=80=99t declare i=
t at all. If the loop is such that the value of end is hoisted into a regis=
ter, it=E2=80=99s likely the same can be done for cont.cend().

for (auto beg =3D cont.cbegin(); beg !=3D cont.cend(); ++beg) {

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_A71B7D2C-FC48-43E5-A9D1-0A8E9795CAF1
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9309=
=E2=80=9303, at 11:07 PM, Arthur Tchaikovsky &lt;<a href=3D"mailto:atch.cpp=
@gmail.com" class=3D"">atch.cpp@gmail.com</a>&gt; wrote:</div><br class=3D"=
Apple-interchange-newline"><div class=3D""><span style=3D"font-family: Helv=
etica; font-size: 12px; font-style: normal; font-variant: normal; font-weig=
ht: normal; letter-spacing: normal; line-height: normal; orphans: auto; tex=
t-align: start; text-indent: 0px; text-transform: none; white-space: normal=
; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: n=
one; display: inline !important;" class=3D"">Any thoughts?</span><br style=
=3D"font-family: Helvetica; font-size: 12px; font-style: normal; font-varia=
nt: normal; font-weight: normal; letter-spacing: normal; line-height: norma=
l; orphans: auto; text-align: start; text-indent: 0px; text-transform: none=
; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke=
-width: 0px;" class=3D""></div></blockquote></div><br class=3D""><div class=
=3D"">The Ranges TS will solve this. It models just such a half-const itera=
tor pair.</div><div class=3D""><br class=3D""></div><div class=3D"">In the =
meantime, you can do this:</div><div class=3D""><br class=3D""></div><div c=
lass=3D""><font face=3D"Courier" class=3D"">for (auto beg =3D cont.cbegin()=
, end_var =3D cont.cend(); beg !=3D end; ++beg) {<br class=3D""></font></di=
v><div class=3D""><font face=3D"Courier" class=3D"">&nbsp; &nbsp; auto cons=
t &amp; end =3D end_var;</font></div><div class=3D""><br class=3D""></div><=
div class=3D"">Or, if <font face=3D"Courier" class=3D"">end</font> is liter=
ally initialized by <font face=3D"Courier" class=3D"">cont.cend()</font>, d=
on=E2=80=99t declare it at all. If the loop is such that the value of <font=
 face=3D"Courier" class=3D"">end</font> is hoisted into a register, it=E2=
=80=99s likely the same can be done for <font face=3D"Courier" class=3D"">c=
ont.cend()</font>.</div><div class=3D""><br class=3D""></div><div class=3D"=
"><div class=3D""><font face=3D"Courier" class=3D"">for (auto beg =3D cont.=
cbegin(); beg !=3D&nbsp;</font><span style=3D"font-family: Courier;" class=
=3D"">cont.cend()</span><font face=3D"Courier" class=3D"">; ++beg) {</font>=
</div><div class=3D""><br class=3D""></div></div></body></html>

<p></p>

-- <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+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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_A71B7D2C-FC48-43E5-A9D1-0A8E9795CAF1--

.


Author: Arthur Tchaikovsky <atch.cpp@gmail.com>
Date: Fri, 4 Sep 2015 02:22:22 -0700 (PDT)
Raw View
------=_Part_120_285766657.1441358542621
Content-Type: multipart/alternative;
 boundary="----=_Part_121_1009682515.1441358542621"

------=_Part_121_1009682515.1441358542621
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi, that first example of yours doesn't compile, and it simply looks=20
unnatural. The second example misses the optimization opportunity, what if=
=20
I have to call end 1'000'000 times, and have similar loops in couple of=20
other places in my code?=20


On Friday, 4 September 2015 03:08:04 UTC+1, David Krauss wrote:
>
>
> On 2015=E2=80=9309=E2=80=9303, at 11:07 PM, Arthur Tchaikovsky <atch...@g=
mail.com=20
> <javascript:>> wrote:
>
> Any thoughts?
>
>
> The Ranges TS will solve this. It models just such a half-const iterator=
=20
> pair.
>
> In the meantime, you can do this:
>
> for (auto beg =3D cont.cbegin(), end_var =3D cont.cend(); beg !=3D end; +=
+beg) {
>     auto const & end =3D end_var;
>
> Or, if end is literally initialized by cont.cend(), don=E2=80=99t declare=
 it at=20
> all. If the loop is such that the value of end is hoisted into a=20
> register, it=E2=80=99s likely the same can be done for cont.cend().
>
> for (auto beg =3D cont.cbegin(); beg !=3D cont.cend(); ++beg) {
>
>

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr">Hi, that first example of yours doesn&#39;t compile, and i=
t simply looks unnatural. The second example misses the optimization opport=
unity, what if I have to call end 1&#39;000&#39;000 times, and have similar=
 loops in couple of other places in my code? <br><br><br>On Friday, 4 Septe=
mber 2015 03:08:04 UTC+1, David Krauss  wrote:<blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padd=
ing-left: 1ex;"><div style=3D"word-wrap:break-word"><br><div><blockquote ty=
pe=3D"cite"><div>On 2015=E2=80=9309=E2=80=9303, at 11:07 PM, Arthur Tchaiko=
vsky &lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D=
"9AUuiedfAAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:=
&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return tru=
e;">atch...@gmail.com</a>&gt; wrote:</div><br><div><span style=3D"font-fami=
ly:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weig=
ht:normal;letter-spacing:normal;line-height:normal;text-align:start;text-in=
dent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none=
;display:inline!important">Any thoughts?</span><br style=3D"font-family:Hel=
vetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:nor=
mal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0=
px;text-transform:none;white-space:normal;word-spacing:0px"></div></blockqu=
ote></div><br><div>The Ranges TS will solve this. It models just such a hal=
f-const iterator pair.</div><div><br></div><div>In the meantime, you can do=
 this:</div><div><br></div><div><font face=3D"Courier">for (auto beg =3D co=
nt.cbegin(), end_var =3D cont.cend(); beg !=3D end; ++beg) {<br></font></di=
v><div><font face=3D"Courier">=C2=A0 =C2=A0 auto const &amp; end =3D end_va=
r;</font></div><div><br></div><div>Or, if <font face=3D"Courier">end</font>=
 is literally initialized by <font face=3D"Courier">cont.cend()</font>, don=
=E2=80=99t declare it at all. If the loop is such that the value of <font f=
ace=3D"Courier">end</font> is hoisted into a register, it=E2=80=99s likely =
the same can be done for <font face=3D"Courier">cont.cend()</font>.</div><d=
iv><br></div><div><div><font face=3D"Courier">for (auto beg =3D cont.cbegin=
(); beg !=3D=C2=A0</font><span style=3D"font-family:Courier">cont.cend()</s=
pan><font face=3D"Courier">; ++beg) {</font></div><div><br></div></div></di=
v></blockquote></div>

<p></p>

-- <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+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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_121_1009682515.1441358542621--
------=_Part_120_285766657.1441358542621--

.


Author: Arthur Tchaikovsky <atch.cpp@gmail.com>
Date: Fri, 4 Sep 2015 02:28:07 -0700 (PDT)
Raw View
------=_Part_93_378256685.1441358887272
Content-Type: multipart/alternative;
 boundary="----=_Part_94_435848137.1441358887273"

------=_Part_94_435848137.1441358887273
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi, Exactly, instinctively that should work, but it doesn't. It would be=20
nice if it did though.
And yes, I need access to iterators.
Thanks

On Friday, 4 September 2015 02:49:15 UTC+1, Klaim - Jo=C3=ABl Lamotte wrote=
:
>
>
>
> On 3 September 2015 at 17:07, Arthur Tchaikovsky <atch...@gmail.com=20
> <javascript:>> wrote:
>
>> Hi guys,=20
>> I very often come across a situation where I need to declare two=20
>> iterators inside a loop, namely beg and end of some container and I want=
=20
>> only the beg iterator to be able to change position, but the end iterato=
r=20
>> to be let's say const. At this moment AFAIK the workaround for it would =
be:
>>
>> const auto end =3D cont.cend();
>> for (auto beg =3D cont.cbegin(); beg !=3D end; ++beg)
>> {
>> /*here inside this loop I only ever need to be able to move beg iterator=
=20
>> but I want to make sure that end iterator is never moved from initial=20
>> position*/
>> }
>>
>> The above approach has few issues namely introducing end into the scope=
=20
>> where it logically doesn't belong. I could of course introduce another=
=20
>> scope but this seem like unnatural solution for a simple problem.
>> I'd like to be able to write:
>>
>> for (auto beg =3D cont.cbegin(), const end =3D cont.cend(); beg !=3D end=
; ++beg)
>> {
>> /*Here the end iterator is of this same type as beg but it is also made=
=20
>> const so there is no possibility of me accidentally move this iterator*/
>> }
>>
>> Any thoughts?
>> =20
>>
>
> I instinctively thought that this could work but apparently (gcc tells me=
)=20
> it does not:
>
>     for (auto beg =3D cont.cbegin(), const auto end =3D cont.cend(); beg =
!=3D=20
> end; ++beg)
>
> I'm assuming here that you really need access to the iterators so=20
> for-range-loop and for_each are not a solution?
>
>
>
>

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr">Hi, Exactly, instinctively that should work, but it doesn&=
#39;t. It would be nice if it did though.<br>And yes, I need access to iter=
ators.<br>Thanks<br><br>On Friday, 4 September 2015 02:49:15 UTC+1, Klaim -=
 Jo=C3=ABl Lamotte  wrote:<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"><br><div><br><div class=3D"gmail_quote">On 3 September 2015 at=
 17:07, Arthur Tchaikovsky <span dir=3D"ltr">&lt;<a href=3D"javascript:" ta=
rget=3D"_blank" gdf-obfuscated-mailto=3D"Xo25ieBeAAAJ" rel=3D"nofollow" onm=
ousedown=3D"this.href=3D&#39;javascript:&#39;;return true;" onclick=3D"this=
..href=3D&#39;javascript:&#39;;return true;">atch...@gmail.com</a>&gt;</span=
> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
..8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-s=
tyle:solid;padding-left:1ex"><div dir=3D"ltr">Hi guys, <br>I very often com=
e across a situation where I need to declare two iterators inside a loop, n=
amely beg and end of some container and I want only the beg iterator to be =
able to change position, but the end iterator to be let&#39;s say const. At=
 this moment AFAIK the workaround for it would be:<br><br>const auto end =
=3D cont.cend();<br>for (auto beg =3D cont.cbegin(); beg !=3D end; ++beg)<b=
r>{<br>/*here inside this loop I only ever need to be able to move beg iter=
ator but I want to make sure that end iterator is never moved from initial =
position*/<br>}<br><br>The above approach has few issues namely introducing=
 end into the scope where it logically doesn&#39;t belong. I could of cours=
e introduce another scope but this seem like unnatural solution for a simpl=
e problem.<br>I&#39;d like to be able to write:<br><br>for (auto beg =3D co=
nt.cbegin(), const end =3D cont.cend(); beg !=3D end; ++beg)<br>{<br>/*Here=
 the end iterator is of this same type as beg but it is also made const so =
there is no possibility of me accidentally move this iterator*/<br>}<br><br=
></div></blockquote><blockquote class=3D"gmail_quote" style=3D"margin:0px 0=
px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);borde=
r-left-style:solid;padding-left:1ex"><div dir=3D"ltr">Any thoughts?<span><f=
ont color=3D"#888888"><br>=C2=A0<br></font></span></div></blockquote><div><=
br></div><div>I instinctively thought that this could work but apparently (=
gcc tells me) it does not:</div><div><br></div><div>=C2=A0 =C2=A0 for (auto=
 beg =3D cont.cbegin(), const auto end =3D cont.cend(); beg !=3D end; ++beg=
)<br></div><div><br></div><div>I&#39;m assuming here that you really need a=
ccess to the iterators so for-range-loop and for_each are not a solution?</=
div><div><br></div><div><br></div><div><br></div></div></div></div>
</blockquote></div>

<p></p>

-- <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+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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_94_435848137.1441358887273--
------=_Part_93_378256685.1441358887272--

.


Author: Arthur Tchaikovsky <atch.cpp@gmail.com>
Date: Fri, 4 Sep 2015 03:10:43 -0700 (PDT)
Raw View
------=_Part_286_1080149981.1441361443535
Content-Type: multipart/alternative;
 boundary="----=_Part_287_602160311.1441361443536"

------=_Part_287_602160311.1441361443536
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

@David, Another point. I'm sorry to say that and I try to be really polite,=
=20
but your first example should be an example of how one *never, ever, ever*=
=20
should write a code. Why? Let me tell you why, because end is giving the=20
impression that it cannot change its value because it is const, but when=20
one changes value of end_var, what happens to the value of end? Hum? What=
=20
happens to that value? It friking changes because it is a reference to=20
end_var. This code is at best misleading, and definitely dangerous. Should=
=20
never happen.

On Friday, 4 September 2015 03:08:04 UTC+1, David Krauss wrote:
>
>
> On 2015=E2=80=9309=E2=80=9303, at 11:07 PM, Arthur Tchaikovsky <atch...@g=
mail.com=20
> <javascript:>> wrote:
>
> Any thoughts?
>
>
> The Ranges TS will solve this. It models just such a half-const iterator=
=20
> pair.
>
> In the meantime, you can do this:
>
> for (auto beg =3D cont.cbegin(), end_var =3D cont.cend(); beg !=3D end; +=
+beg) {
>     auto const & end =3D end_var;
>
> Or, if end is literally initialized by cont.cend(), don=E2=80=99t declare=
 it at=20
> all. If the loop is such that the value of end is hoisted into a=20
> register, it=E2=80=99s likely the same can be done for cont.cend().
>
> for (auto beg =3D cont.cbegin(); beg !=3D cont.cend(); ++beg) {
>
>

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr">@David, Another point. I&#39;m sorry to say that and I try=
 to be really polite, but your first example should be an example of how on=
e *never, ever, ever* should write a code. Why? Let me tell you why, becaus=
e end is giving the impression that it cannot change its value because it i=
s const, but when one changes value of end_var, what happens to the value o=
f end? Hum? What happens to that value? It friking changes because it is a =
reference to end_var. This code is at best misleading, and definitely dange=
rous. Should never happen.<br><br>On Friday, 4 September 2015 03:08:04 UTC+=
1, David Krauss  wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div st=
yle=3D"word-wrap:break-word"><br><div><blockquote type=3D"cite"><div>On 201=
5=E2=80=9309=E2=80=9303, at 11:07 PM, Arthur Tchaikovsky &lt;<a href=3D"jav=
ascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"9AUuiedfAAAJ" rel=3D"n=
ofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return true;" onc=
lick=3D"this.href=3D&#39;javascript:&#39;;return true;">atch...@gmail.com</=
a>&gt; wrote:</div><br><div><span style=3D"font-family:Helvetica;font-size:=
12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacin=
g:normal;line-height:normal;text-align:start;text-indent:0px;text-transform=
:none;white-space:normal;word-spacing:0px;float:none;display:inline!importa=
nt">Any thoughts?</span><br style=3D"font-family:Helvetica;font-size:12px;f=
ont-style:normal;font-variant:normal;font-weight:normal;letter-spacing:norm=
al;line-height:normal;text-align:start;text-indent:0px;text-transform:none;=
white-space:normal;word-spacing:0px"></div></blockquote></div><br><div>The =
Ranges TS will solve this. It models just such a half-const iterator pair.<=
/div><div><br></div><div>In the meantime, you can do this:</div><div><br></=
div><div><font face=3D"Courier">for (auto beg =3D cont.cbegin(), end_var =
=3D cont.cend(); beg !=3D end; ++beg) {<br></font></div><div><font face=3D"=
Courier">=C2=A0 =C2=A0 auto const &amp; end =3D end_var;</font></div><div><=
br></div><div>Or, if <font face=3D"Courier">end</font> is literally initial=
ized by <font face=3D"Courier">cont.cend()</font>, don=E2=80=99t declare it=
 at all. If the loop is such that the value of <font face=3D"Courier">end</=
font> is hoisted into a register, it=E2=80=99s likely the same can be done =
for <font face=3D"Courier">cont.cend()</font>.</div><div><br></div><div><di=
v><font face=3D"Courier">for (auto beg =3D cont.cbegin(); beg !=3D=C2=A0</f=
ont><span style=3D"font-family:Courier">cont.cend()</span><font face=3D"Cou=
rier">; ++beg) {</font></div><div><br></div></div></div></blockquote></div>

<p></p>

-- <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+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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_287_602160311.1441361443536--
------=_Part_286_1080149981.1441361443535--

.


Author: David Krauss <potswa@gmail.com>
Date: Fri, 4 Sep 2015 18:51:45 +0800
Raw View
--Apple-Mail=_B460AE63-6A2F-4E7F-992C-1840AE19A645
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

But, you assert it=E2=80=99s a good idea to declare local variables of diff=
erent types in one declaration? (By the way, there is a way to declare thos=
e two variables in a loop initialization declaration, with or without a ran=
ge class template.)

Don=E2=80=99t worry, I don=E2=80=99t write things like that. When it comes =
to performance optimization, the first step is to learn where cycles are be=
ing spent. const.end() almost invariably expands to a simple member access,=
 and barring aliasing, that can be hoisted out of the loop.

Worrying that someone is going to assign to the end iterator isn=E2=80=99t =
premature optimization, though, it=E2=80=99s paranoia. Both tend to drive c=
ode crazy.


> On 2015=E2=80=9309=E2=80=9304, at 6:10 PM, Arthur Tchaikovsky <atch.cpp@g=
mail.com> wrote:
>=20
> @David, Another point. I'm sorry to say that and I try to be really polit=
e, but your first example should be an example of how one *never, ever, eve=
r* should write a code. Why? Let me tell you why, because end is giving the=
 impression that it cannot change its value because it is const, but when o=
ne changes value of end_var, what happens to the value of end? Hum? What ha=
ppens to that value? It friking changes because it is a reference to end_va=
r. This code is at best misleading, and definitely dangerous. Should never =
happen.
>=20
> On Friday, 4 September 2015 03:08:04 UTC+1, David Krauss wrote:
>=20
>> On 2015=E2=80=9309=E2=80=9303, at 11:07 PM, Arthur Tchaikovsky <atch...@=
gmail.com <>> wrote:
>>=20
>> Any thoughts?
>=20
> The Ranges TS will solve this. It models just such a half-const iterator =
pair.
>=20
> In the meantime, you can do this:
>=20
> for (auto beg =3D cont.cbegin(), end_var =3D cont.cend(); beg !=3D end; +=
+beg) {
>     auto const & end =3D end_var;
>=20
> Or, if end is literally initialized by cont.cend(), don=E2=80=99t declare=
 it at all. If the loop is such that the value of end is hoisted into a reg=
ister, it=E2=80=99s likely the same can be done for cont.cend().
>=20
> for (auto beg =3D cont.cbegin(); beg !=3D cont.cend(); ++beg) {
>=20
>=20
> --=20
>=20
> ---=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=
 email to std-proposals+unsubscribe@isocpp.org <mailto:std-proposals+unsubs=
cribe@isocpp.org>.
> To post to this group, send email to std-proposals@isocpp.org <mailto:std=
-proposals@isocpp.org>.
> Visit this group at http://groups.google.com/a/isocpp.org/group/std-propo=
sals/ <http://groups.google.com/a/isocpp.org/group/std-proposals/>.

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_B460AE63-6A2F-4E7F-992C-1840AE19A645
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D"">But, you assert it=
=E2=80=99s a good idea to declare local variables of different types in one=
 declaration? (By the way, there <i class=3D"">is</i>&nbsp;a way to declare=
 those two variables in a loop initialization declaration, with or without =
a range class template.)<div class=3D""><br class=3D""></div><div class=3D"=
">Don=E2=80=99t worry, I don=E2=80=99t write things like that. When it come=
s to performance optimization, the first step is to learn where cycles are =
being spent. <font face=3D"Courier" class=3D"">const.end()</font>&nbsp;almo=
st invariably expands to a simple member access, and barring aliasing, that=
 can be hoisted out of the loop.</div><div class=3D""><br class=3D""></div>=
<div class=3D"">Worrying that someone is going to assign to the end iterato=
r isn=E2=80=99t premature optimization, though, it=E2=80=99s paranoia. Both=
 tend to drive code crazy.</div><div class=3D""><br class=3D""></div><div c=
lass=3D""><br class=3D""><div><blockquote type=3D"cite" class=3D""><div cla=
ss=3D"">On 2015=E2=80=9309=E2=80=9304, at 6:10 PM, Arthur Tchaikovsky &lt;<=
a href=3D"mailto:atch.cpp@gmail.com" class=3D"">atch.cpp@gmail.com</a>&gt; =
wrote:</div><br class=3D"Apple-interchange-newline"><div class=3D""><div di=
r=3D"ltr" style=3D"font-family: Helvetica; font-size: 12px; font-style: nor=
mal; font-variant: normal; font-weight: normal; letter-spacing: normal; lin=
e-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-=
transform: none; white-space: normal; widows: auto; word-spacing: 0px; -web=
kit-text-stroke-width: 0px;" class=3D"">@David, Another point. I'm sorry to=
 say that and I try to be really polite, but your first example should be a=
n example of how one *never, ever, ever* should write a code. Why? Let me t=
ell you why, because end is giving the impression that it cannot change its=
 value because it is const, but when one changes value of end_var, what hap=
pens to the value of end? Hum? What happens to that value? It friking chang=
es because it is a reference to end_var. This code is at best misleading, a=
nd definitely dangerous. Should never happen.<br class=3D""><br class=3D"">=
On Friday, 4 September 2015 03:08:04 UTC+1, David Krauss wrote:<blockquote =
class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; border-left-width=
: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; pad=
ding-left: 1ex;"><div style=3D"word-wrap: break-word;" class=3D""><br class=
=3D""><div class=3D""><blockquote type=3D"cite" class=3D""><div class=3D"">=
On 2015=E2=80=9309=E2=80=9303, at 11:07 PM, Arthur Tchaikovsky &lt;<a targe=
t=3D"_blank" gdf-obfuscated-mailto=3D"9AUuiedfAAAJ" rel=3D"nofollow" class=
=3D"">atch...@gmail.com</a>&gt; wrote:</div><br class=3D""><div class=3D"">=
<span style=3D"font-family: Helvetica; font-size: 12px; font-style: normal;=
 font-variant: normal; font-weight: normal; letter-spacing: normal; line-he=
ight: normal; text-align: start; text-indent: 0px; text-transform: none; wh=
ite-space: normal; word-spacing: 0px; float: none; display: inline !importa=
nt;" class=3D"">Any thoughts?</span><br style=3D"font-family: Helvetica; fo=
nt-size: 12px; font-style: normal; font-variant: normal; font-weight: norma=
l; letter-spacing: normal; line-height: normal; text-align: start; text-ind=
ent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" cl=
ass=3D""></div></blockquote></div><br class=3D""><div class=3D"">The Ranges=
 TS will solve this. It models just such a half-const iterator pair.</div><=
div class=3D""><br class=3D""></div><div class=3D"">In the meantime, you ca=
n do this:</div><div class=3D""><br class=3D""></div><div class=3D""><font =
face=3D"Courier" class=3D"">for (auto beg =3D cont.cbegin(), end_var =3D co=
nt.cend(); beg !=3D end; ++beg) {<br class=3D""></font></div><div class=3D"=
"><font face=3D"Courier" class=3D"">&nbsp; &nbsp;<span class=3D"Apple-conve=
rted-space">&nbsp;</span>auto const &amp; end =3D end_var;</font></div><div=
 class=3D""><br class=3D""></div><div class=3D"">Or, if<span class=3D"Apple=
-converted-space">&nbsp;</span><font face=3D"Courier" class=3D"">end</font>=
<span class=3D"Apple-converted-space">&nbsp;</span>is literally initialized=
 by<span class=3D"Apple-converted-space">&nbsp;</span><font face=3D"Courier=
" class=3D"">cont.cend()</font>, don=E2=80=99t declare it at all. If the lo=
op is such that the value of<span class=3D"Apple-converted-space">&nbsp;</s=
pan><font face=3D"Courier" class=3D"">end</font><span class=3D"Apple-conver=
ted-space">&nbsp;</span>is hoisted into a register, it=E2=80=99s likely the=
 same can be done for<span class=3D"Apple-converted-space">&nbsp;</span><fo=
nt face=3D"Courier" class=3D"">cont.cend()</font>.</div><div class=3D""><br=
 class=3D""></div><div class=3D""><div class=3D""><font face=3D"Courier" cl=
ass=3D"">for (auto beg =3D cont.cbegin(); beg !=3D&nbsp;</font><span style=
=3D"font-family: Courier;" class=3D"">cont.cend()</span><font face=3D"Couri=
er" class=3D"">; ++beg) {</font></div><div class=3D""><br class=3D""></div>=
</div></div></blockquote></div><div style=3D"font-family: Helvetica; font-s=
ize: 12px; font-style: normal; font-variant: normal; font-weight: normal; l=
etter-spacing: normal; line-height: normal; orphans: auto; text-align: star=
t; text-indent: 0px; text-transform: none; white-space: normal; widows: aut=
o; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=3D""><br class=
=3D"webkit-block-placeholder"></div><span style=3D"font-family: Helvetica; =
font-size: 12px; font-style: normal; font-variant: normal; font-weight: nor=
mal; letter-spacing: normal; line-height: normal; orphans: auto; text-align=
: start; text-indent: 0px; text-transform: none; white-space: normal; widow=
s: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; di=
splay: inline !important;" class=3D"">--<span class=3D"Apple-converted-spac=
e">&nbsp;</span></span><br style=3D"font-family: Helvetica; font-size: 12px=
; font-style: normal; font-variant: normal; font-weight: normal; letter-spa=
cing: normal; line-height: normal; orphans: auto; text-align: start; text-i=
ndent: 0px; text-transform: none; white-space: normal; widows: auto; word-s=
pacing: 0px; -webkit-text-stroke-width: 0px;" class=3D""><br style=3D"font-=
family: Helvetica; font-size: 12px; font-style: normal; font-variant: norma=
l; font-weight: normal; letter-spacing: normal; line-height: normal; orphan=
s: auto; text-align: start; text-indent: 0px; text-transform: none; white-s=
pace: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0=
px;" class=3D""><span style=3D"font-family: Helvetica; font-size: 12px; fon=
t-style: normal; font-variant: normal; font-weight: normal; letter-spacing:=
 normal; line-height: normal; orphans: auto; text-align: start; text-indent=
: 0px; text-transform: none; white-space: normal; widows: auto; word-spacin=
g: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !impor=
tant;" class=3D"">---<span class=3D"Apple-converted-space">&nbsp;</span></s=
pan><br style=3D"font-family: Helvetica; font-size: 12px; font-style: norma=
l; font-variant: normal; font-weight: normal; letter-spacing: normal; line-=
height: normal; orphans: auto; text-align: start; text-indent: 0px; text-tr=
ansform: none; white-space: normal; widows: auto; word-spacing: 0px; -webki=
t-text-stroke-width: 0px;" class=3D""><span style=3D"font-family: Helvetica=
; font-size: 12px; font-style: normal; font-variant: normal; font-weight: n=
ormal; letter-spacing: normal; line-height: normal; orphans: auto; text-ali=
gn: start; text-indent: 0px; text-transform: none; white-space: normal; wid=
ows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; =
display: inline !important;" class=3D"">You received this message because y=
ou are subscribed to the Google Groups "ISO C++ Standard - Future Proposals=
" group.</span><br style=3D"font-family: Helvetica; font-size: 12px; font-s=
tyle: normal; font-variant: normal; font-weight: normal; letter-spacing: no=
rmal; line-height: normal; orphans: auto; text-align: start; text-indent: 0=
px; text-transform: none; white-space: normal; widows: auto; word-spacing: =
0px; -webkit-text-stroke-width: 0px;" class=3D""><span style=3D"font-family=
: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; fon=
t-weight: normal; letter-spacing: normal; line-height: normal; orphans: aut=
o; text-align: start; text-indent: 0px; text-transform: none; white-space: =
normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; fl=
oat: none; display: inline !important;" class=3D"">To unsubscribe from this=
 group and stop receiving emails from it, send an email to<span class=3D"Ap=
ple-converted-space">&nbsp;</span></span><a href=3D"mailto:std-proposals+un=
subscribe@isocpp.org" style=3D"font-family: Helvetica; font-size: 12px; fon=
t-style: normal; font-variant: normal; font-weight: normal; letter-spacing:=
 normal; line-height: normal; orphans: auto; text-align: start; text-indent=
: 0px; text-transform: none; white-space: normal; widows: auto; word-spacin=
g: 0px; -webkit-text-stroke-width: 0px;" class=3D"">std-proposals+unsubscri=
be@isocpp.org</a><span style=3D"font-family: Helvetica; font-size: 12px; fo=
nt-style: normal; font-variant: normal; font-weight: normal; letter-spacing=
: normal; line-height: normal; orphans: auto; text-align: start; text-inden=
t: 0px; text-transform: none; white-space: normal; widows: auto; word-spaci=
ng: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !impo=
rtant;" class=3D"">.</span><br style=3D"font-family: Helvetica; font-size: =
12px; font-style: normal; font-variant: normal; font-weight: normal; letter=
-spacing: normal; line-height: normal; orphans: auto; text-align: start; te=
xt-indent: 0px; text-transform: none; white-space: normal; widows: auto; wo=
rd-spacing: 0px; -webkit-text-stroke-width: 0px;" class=3D""><span style=3D=
"font-family: Helvetica; font-size: 12px; font-style: normal; font-variant:=
 normal; font-weight: normal; letter-spacing: normal; line-height: normal; =
orphans: auto; text-align: start; text-indent: 0px; text-transform: none; w=
hite-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-wi=
dth: 0px; float: none; display: inline !important;" class=3D"">To post to t=
his group, send email to<span class=3D"Apple-converted-space">&nbsp;</span>=
</span><a href=3D"mailto:std-proposals@isocpp.org" style=3D"font-family: He=
lvetica; font-size: 12px; font-style: normal; font-variant: normal; font-we=
ight: normal; letter-spacing: normal; line-height: normal; orphans: auto; t=
ext-align: start; text-indent: 0px; text-transform: none; white-space: norm=
al; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=
=3D"">std-proposals@isocpp.org</a><span style=3D"font-family: Helvetica; fo=
nt-size: 12px; font-style: normal; font-variant: normal; font-weight: norma=
l; letter-spacing: normal; line-height: normal; orphans: auto; text-align: =
start; text-indent: 0px; text-transform: none; white-space: normal; widows:=
 auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; disp=
lay: inline !important;" class=3D"">.</span><br style=3D"font-family: Helve=
tica; font-size: 12px; font-style: normal; font-variant: normal; font-weigh=
t: normal; letter-spacing: normal; line-height: normal; orphans: auto; text=
-align: start; text-indent: 0px; text-transform: none; white-space: normal;=
 widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=3D=
""><span style=3D"font-family: Helvetica; font-size: 12px; font-style: norm=
al; font-variant: normal; font-weight: normal; letter-spacing: normal; line=
-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-t=
ransform: none; white-space: normal; widows: auto; word-spacing: 0px; -webk=
it-text-stroke-width: 0px; float: none; display: inline !important;" class=
=3D"">Visit this group at<span class=3D"Apple-converted-space">&nbsp;</span=
></span><a href=3D"http://groups.google.com/a/isocpp.org/group/std-proposal=
s/" style=3D"font-family: Helvetica; font-size: 12px; font-style: normal; f=
ont-variant: normal; font-weight: normal; letter-spacing: normal; line-heig=
ht: normal; orphans: auto; text-align: start; text-indent: 0px; text-transf=
orm: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-te=
xt-stroke-width: 0px;" class=3D"">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a><span style=3D"font-family: Helvetica; font-size: 12px=
; font-style: normal; font-variant: normal; font-weight: normal; letter-spa=
cing: normal; line-height: normal; orphans: auto; text-align: start; text-i=
ndent: 0px; text-transform: none; white-space: normal; widows: auto; word-s=
pacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !=
important;" class=3D"">.</span></div></blockquote></div><br class=3D""></di=
v></body></html>

<p></p>

-- <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+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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_B460AE63-6A2F-4E7F-992C-1840AE19A645--

.


Author: Arthur Tchaikovsky <atch.cpp@gmail.com>
Date: Fri, 4 Sep 2015 04:09:20 -0700 (PDT)
Raw View
------=_Part_696_819789351.1441364960797
Content-Type: multipart/alternative;
 boundary="----=_Part_697_1495508225.1441364960797"

------=_Part_697_1495508225.1441364960797
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

No, I don't assert that it=E2=80=99s a good idea to declare local variables=
 of=20
different types in one declaration. But what *I assert* is, that it is a=20
good idea to allow more than one type definition in for loop in a sense=20
that int and const int are two different types but it still allows me to=20
compare them, so people are able to:
a) write safe code
b) write simple code
c) compare const with non-const


for (auto beg =3D cont.cbeg(), const auto end =3D cont.cend() ; beg !=3D en=
d;=20
++beg)
{
}

surely this^^^ doesn't look unreasonable?
Is this really something unreasonable to ask for?

On Friday, 4 September 2015 11:51:55 UTC+1, David Krauss wrote:
>
> But, you assert it=E2=80=99s a good idea to declare local variables of di=
fferent=20
> types in one declaration? (By the way, there *is* a way to declare those=
=20
> two variables in a loop initialization declaration, with or without a ran=
ge=20
> class template.)
>
> Don=E2=80=99t worry, I don=E2=80=99t write things like that. When it come=
s to performance=20
> optimization, the first step is to learn where cycles are being spent.=20
> const.end() almost invariably expands to a simple member access, and=20
> barring aliasing, that can be hoisted out of the loop.
>
> Worrying that someone is going to assign to the end iterator isn=E2=80=99=
t=20
> premature optimization, though, it=E2=80=99s paranoia. Both tend to drive=
 code=20
> crazy.
>
>
> On 2015=E2=80=9309=E2=80=9304, at 6:10 PM, Arthur Tchaikovsky <atch...@gm=
ail.com=20
> <javascript:>> wrote:
>
> @David, Another point. I'm sorry to say that and I try to be really=20
> polite, but your first example should be an example of how one *never,=20
> ever, ever* should write a code. Why? Let me tell you why, because end is=
=20
> giving the impression that it cannot change its value because it is const=
,=20
> but when one changes value of end_var, what happens to the value of end?=
=20
> Hum? What happens to that value? It friking changes because it is a=20
> reference to end_var. This code is at best misleading, and definitely=20
> dangerous. Should never happen.
>
> On Friday, 4 September 2015 03:08:04 UTC+1, David Krauss wrote:
>>
>>
>> On 2015=E2=80=9309=E2=80=9303, at 11:07 PM, Arthur Tchaikovsky <atch...@=
gmail.com> wrote:
>>
>> Any thoughts?
>>
>>
>> The Ranges TS will solve this. It models just such a half-const iterator=
=20
>> pair.
>>
>> In the meantime, you can do this:
>>
>> for (auto beg =3D cont.cbegin(), end_var =3D cont.cend(); beg !=3D end; =
++beg) {
>>     auto const & end =3D end_var;
>>
>> Or, if end is literally initialized by cont.cend(), don=E2=80=99t declar=
e it at=20
>> all. If the loop is such that the value of end is hoisted into a=20
>> register, it=E2=80=99s likely the same can be done for cont.cend().
>>
>> for (auto beg =3D cont.cbegin(); beg !=3D cont.cend(); ++beg) {
>>
>>
> --=20
>
> ---=20
> You received this message because you are subscribed to the Google Groups=
=20
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an=
=20
> email to std-proposal...@isocpp.org <javascript:>.
> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
> Visit this group at=20
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>
>
>

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr">No, I don&#39;t assert that  it=E2=80=99s a good idea to d=
eclare local variables of different types in one declaration. But what *I a=
ssert* is, that it is a good idea to allow more than one type definition in=
 for loop in a sense that int and const int are two different types but it =
still allows me to compare them, so people are able to:<br>a) write safe co=
de<br>b) write simple code<br>c) compare const with non-const<br><br><br>fo=
r (auto beg =3D cont.cbeg(), const auto end =3D cont.cend() ; beg !=3D end;=
 ++beg)<br>{<br>}<br><br>surely this^^^ doesn&#39;t look unreasonable?<br>I=
s this really something unreasonable to ask for?<br><br>On Friday, 4 Septem=
ber 2015 11:51:55 UTC+1, David Krauss  wrote:<blockquote class=3D"gmail_quo=
te" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;paddi=
ng-left: 1ex;"><div style=3D"word-wrap:break-word">But, you assert it=E2=80=
=99s a good idea to declare local variables of different types in one decla=
ration? (By the way, there <i>is</i>=C2=A0a way to declare those two variab=
les in a loop initialization declaration, with or without a range class tem=
plate.)<div><br></div><div>Don=E2=80=99t worry, I don=E2=80=99t write thing=
s like that. When it comes to performance optimization, the first step is t=
o learn where cycles are being spent. <font face=3D"Courier">const.end()</f=
ont>=C2=A0almost invariably expands to a simple member access, and barring =
aliasing, that can be hoisted out of the loop.</div><div><br></div><div>Wor=
rying that someone is going to assign to the end iterator isn=E2=80=99t pre=
mature optimization, though, it=E2=80=99s paranoia. Both tend to drive code=
 crazy.</div><div><br></div><div><br><div><blockquote type=3D"cite"><div>On=
 2015=E2=80=9309=E2=80=9304, at 6:10 PM, Arthur Tchaikovsky &lt;<a href=3D"=
javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"bSZ8en18AAAJ" rel=
=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return true;=
" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">atch...@gmail.=
com</a>&gt; wrote:</div><br><div><div dir=3D"ltr" style=3D"font-family:Helv=
etica;font-size:12px;font-style:normal;font-variant:normal;font-weight:norm=
al;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0p=
x;text-transform:none;white-space:normal;word-spacing:0px">@David, Another =
point. I&#39;m sorry to say that and I try to be really polite, but your fi=
rst example should be an example of how one *never, ever, ever* should writ=
e a code. Why? Let me tell you why, because end is giving the impression th=
at it cannot change its value because it is const, but when one changes val=
ue of end_var, what happens to the value of end? Hum? What happens to that =
value? It friking changes because it is a reference to end_var. This code i=
s at best misleading, and definitely dangerous. Should never happen.<br><br=
>On Friday, 4 September 2015 03:08:04 UTC+1, David Krauss wrote:<blockquote=
 class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:=
1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left=
:1ex"><div style=3D"word-wrap:break-word"><br><div><blockquote type=3D"cite=
"><div>On 2015=E2=80=9309=E2=80=9303, at 11:07 PM, Arthur Tchaikovsky &lt;<=
a rel=3D"nofollow">atch...@gmail.com</a>&gt; wrote:</div><br><div><span sty=
le=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-variant:n=
ormal;font-weight:normal;letter-spacing:normal;line-height:normal;text-alig=
n:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing=
:0px;float:none;display:inline!important">Any thoughts?</span><br style=3D"=
font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;=
font-weight:normal;letter-spacing:normal;line-height:normal;text-align:star=
t;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">=
</div></blockquote></div><br><div>The Ranges TS will solve this. It models =
just such a half-const iterator pair.</div><div><br></div><div>In the meant=
ime, you can do this:</div><div><br></div><div><font face=3D"Courier">for (=
auto beg =3D cont.cbegin(), end_var =3D cont.cend(); beg !=3D end; ++beg) {=
<br></font></div><div><font face=3D"Courier">=C2=A0 =C2=A0<span>=C2=A0</spa=
n>auto const &amp; end =3D end_var;</font></div><div><br></div><div>Or, if<=
span>=C2=A0</span><font face=3D"Courier">end</font><span>=C2=A0</span>is li=
terally initialized by<span>=C2=A0</span><font face=3D"Courier">cont.cend()=
</font>, don=E2=80=99t declare it at all. If the loop is such that the valu=
e of<span>=C2=A0</span><font face=3D"Courier">end</font><span>=C2=A0</span>=
is hoisted into a register, it=E2=80=99s likely the same can be done for<sp=
an>=C2=A0</span><font face=3D"Courier">cont.cend()</font>.</div><div><br></=
div><div><div><font face=3D"Courier">for (auto beg =3D cont.cbegin(); beg !=
=3D=C2=A0</font><span style=3D"font-family:Courier">cont.cend()</span><font=
 face=3D"Courier">; ++beg) {</font></div><div><br></div></div></div></block=
quote></div><div style=3D"font-family:Helvetica;font-size:12px;font-style:n=
ormal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-hei=
ght:normal;text-align:start;text-indent:0px;text-transform:none;white-space=
:normal;word-spacing:0px"><br></div><span style=3D"font-family:Helvetica;fo=
nt-size:12px;font-style:normal;font-variant:normal;font-weight:normal;lette=
r-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-t=
ransform:none;white-space:normal;word-spacing:0px;float:none;display:inline=
!important">--<span>=C2=A0</span></span><br style=3D"font-family:Helvetica;=
font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;let=
ter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text=
-transform:none;white-space:normal;word-spacing:0px"><br style=3D"font-fami=
ly:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weig=
ht:normal;letter-spacing:normal;line-height:normal;text-align:start;text-in=
dent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span sty=
le=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-variant:n=
ormal;font-weight:normal;letter-spacing:normal;line-height:normal;text-alig=
n:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing=
:0px;float:none;display:inline!important">---<span>=C2=A0</span></span><br =
style=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-varian=
t:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-a=
lign:start;text-indent:0px;text-transform:none;white-space:normal;word-spac=
ing:0px"><span style=3D"font-family:Helvetica;font-size:12px;font-style:nor=
mal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-heigh=
t:normal;text-align:start;text-indent:0px;text-transform:none;white-space:n=
ormal;word-spacing:0px;float:none;display:inline!important">You received th=
is message because you are subscribed to the Google Groups &quot;ISO C++ St=
andard - Future Proposals&quot; group.</span><br style=3D"font-family:Helve=
tica;font-size:12px;font-style:normal;font-variant:normal;font-weight:norma=
l;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px=
;text-transform:none;white-space:normal;word-spacing:0px"><span style=3D"fo=
nt-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;fo=
nt-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;=
text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;flo=
at:none;display:inline!important">To unsubscribe from this group and stop r=
eceiving emails from it, send an email to<span>=C2=A0</span></span><a href=
=3D"javascript:" style=3D"font-family:Helvetica;font-size:12px;font-style:n=
ormal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-hei=
ght:normal;text-align:start;text-indent:0px;text-transform:none;white-space=
:normal;word-spacing:0px" target=3D"_blank" gdf-obfuscated-mailto=3D"bSZ8en=
18AAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;r=
eturn true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">std=
-proposal...@<wbr>isocpp.org</a><span style=3D"font-family:Helvetica;font-s=
ize:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-sp=
acing:normal;line-height:normal;text-align:start;text-indent:0px;text-trans=
form:none;white-space:normal;word-spacing:0px;float:none;display:inline!imp=
ortant">.</span><br style=3D"font-family:Helvetica;font-size:12px;font-styl=
e:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-=
height:normal;text-align:start;text-indent:0px;text-transform:none;white-sp=
ace:normal;word-spacing:0px"><span style=3D"font-family:Helvetica;font-size=
:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spaci=
ng:normal;line-height:normal;text-align:start;text-indent:0px;text-transfor=
m:none;white-space:normal;word-spacing:0px;float:none;display:inline!import=
ant">To post to this group, send email to<span>=C2=A0</span></span><a href=
=3D"javascript:" style=3D"font-family:Helvetica;font-size:12px;font-style:n=
ormal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-hei=
ght:normal;text-align:start;text-indent:0px;text-transform:none;white-space=
:normal;word-spacing:0px" target=3D"_blank" gdf-obfuscated-mailto=3D"bSZ8en=
18AAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;r=
eturn true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">std=
-pr...@isocpp.org</a><span style=3D"font-family:Helvetica;font-size:12px;fo=
nt-style:normal;font-variant:normal;font-weight:normal;letter-spacing:norma=
l;line-height:normal;text-align:start;text-indent:0px;text-transform:none;w=
hite-space:normal;word-spacing:0px;float:none;display:inline!important">.</=
span><br style=3D"font-family:Helvetica;font-size:12px;font-style:normal;fo=
nt-variant:normal;font-weight:normal;letter-spacing:normal;line-height:norm=
al;text-align:start;text-indent:0px;text-transform:none;white-space:normal;=
word-spacing:0px"><span style=3D"font-family:Helvetica;font-size:12px;font-=
style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;l=
ine-height:normal;text-align:start;text-indent:0px;text-transform:none;whit=
e-space:normal;word-spacing:0px;float:none;display:inline!important">Visit =
this group at<span>=C2=A0</span></span><a href=3D"http://groups.google.com/=
a/isocpp.org/group/std-proposals/" style=3D"font-family:Helvetica;font-size=
:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spaci=
ng:normal;line-height:normal;text-align:start;text-indent:0px;text-transfor=
m:none;white-space:normal;word-spacing:0px" target=3D"_blank" rel=3D"nofoll=
ow" onmousedown=3D"this.href=3D&#39;http://groups.google.com/a/isocpp.org/g=
roup/std-proposals/&#39;;return true;" onclick=3D"this.href=3D&#39;http://g=
roups.google.com/a/isocpp.org/group/std-proposals/&#39;;return true;">http:=
//groups.google.com/a/<wbr>isocpp.org/group/std-<wbr>proposals/</a><span st=
yle=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-variant:=
normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-ali=
gn:start;text-indent:0px;text-transform:none;white-space:normal;word-spacin=
g:0px;float:none;display:inline!important">.</span></div></blockquote></div=
><br></div></div></blockquote></div>

<p></p>

-- <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+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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_697_1495508225.1441364960797--
------=_Part_696_819789351.1441364960797--

.


Author: David Krauss <potswa@gmail.com>
Date: Fri, 4 Sep 2015 21:46:33 +0800
Raw View
--Apple-Mail=_50CAB24D-56C5-4651-B58B-4B096374F8A6
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

If const behaved like * and & in forming compound type declarators, then we=
 could do

int x =3D 2, const y =3D 3;

Sometimes I=E2=80=99ve wanted to write this. (Less as I=E2=80=99ve gotten o=
lder.) Likewise it feels unnatural to me that both variables are const in

int const x =3D 2, y =3D 3;

I guess the odd way of handling const as either a decl-specifier or an opti=
onal tag attached to * is an artifact of its development: It was originally=
 conceived as modifying a declaration, and then extended to apply within ne=
sted pointers.

That said, since pointers are iterators, C++ does have the feature you want=
, at least in some cases:

for ( auto const * beg =3D std::cbegin( arr ), * const end =3D std::cend( a=
rr ); beg !=3D end; ++ beg )

This is already way too clever. Varying the declarators in one declaration =
is a great way to enliven a code review. Putting two autos in there is outr=
ageous. They look like they can deduce to different, non-comparable things,=
 even if in your example they won=E2=80=99t.

For the particular case of a half-const pair of iterators, the solution (if=
 one is desired) is a range class. No need to modify the language to suppor=
t one use case.

template< typename iterator >
struct range {
    iterator first;
    iterator const last;
};

The rest is left as an exercise. Some folks use std::pair< iter, iter const=
 > for this purpose. I wouldn=E2=80=99t.


> On 2015=E2=80=9309=E2=80=9304, at 7:09 PM, Arthur Tchaikovsky <atch.cpp@g=
mail.com> wrote:
>=20
> No, I don't assert that it=E2=80=99s a good idea to declare local variabl=
es of different types in one declaration. But what *I assert* is, that it i=
s a good idea to allow more than one type definition in for loop in a sense=
 that int and const int are two different types but it still allows me to c=
ompare them, so people are able to:
> a) write safe code
> b) write simple code
> c) compare const with non-const
>=20
>=20
> for (auto beg =3D cont.cbeg(), const auto end =3D cont.cend() ; beg !=3D =
end; ++beg)
> {
> }

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_50CAB24D-56C5-4651-B58B-4B096374F8A6
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><div class=3D"">If=
&nbsp;<span style=3D"font-family: Courier;" class=3D"">const</span>&nbsp;be=
haved like <font face=3D"Courier" class=3D"">*</font> and <font face=3D"Cou=
rier" class=3D"">&amp;</font> in forming compound type declarators, then we=
 could do</div><div class=3D""><br class=3D""></div><div class=3D""><font f=
ace=3D"Courier" class=3D"">int x =3D 2, const y =3D 3;</font></div><div cla=
ss=3D""><br class=3D""></div><div class=3D"">Sometimes I=E2=80=99ve wanted =
to write this. (Less as I=E2=80=99ve gotten older.) Likewise it feels unnat=
ural to me that both variables are <font face=3D"Courier" class=3D"">const<=
/font> in</div><div class=3D""><br class=3D""></div><div class=3D""><font f=
ace=3D"Courier" class=3D"">int const x =3D 2, y =3D 3;</font></div><div cla=
ss=3D""><br class=3D""></div><div class=3D"">I guess the odd way of handlin=
g&nbsp;<span style=3D"font-family: Courier;" class=3D"">const</span>&nbsp;a=
s either a decl-specifier or an optional tag attached to <font face=3D"Cour=
ier" class=3D"">*</font>&nbsp;is an artifact of its development: It was ori=
ginally conceived as modifying a declaration, and then extended to apply wi=
thin nested pointers.</div><div class=3D""><br class=3D""></div><div class=
=3D"">That said, since pointers are iterators, C++ does have the feature yo=
u want, at least in some cases:</div><div class=3D""><br class=3D""></div><=
div class=3D""><font face=3D"Courier" class=3D"">for ( auto const * beg =3D=
 std::cbegin( arr ), * const end =3D std::cend( arr ); beg !=3D end; ++ beg=
 )</font></div><div class=3D""><br class=3D""></div><div class=3D"">This is=
 already way too clever. Varying the declarators in one declaration is a gr=
eat way to enliven a code review. Putting two <font face=3D"Courier" class=
=3D"">auto</font>s in there is outrageous. They look like they can deduce t=
o different, non-comparable things, even if in your example they won=E2=80=
=99t.</div><div class=3D""><br class=3D""></div><div class=3D"">For the par=
ticular case of a half-const pair of iterators, the solution (if one is des=
ired) is a range class. No need to modify the language to support one use c=
ase.</div><div class=3D""><br class=3D""></div><div class=3D""><font face=
=3D"Courier" class=3D"">template&lt; typename iterator &gt;</font></div><di=
v class=3D""><font face=3D"Courier" class=3D"">struct range {</font></div><=
div class=3D""><font face=3D"Courier" class=3D"">&nbsp; &nbsp; iterator fir=
st;</font></div><div class=3D""><font face=3D"Courier" class=3D"">&nbsp; &n=
bsp; iterator const last;</font></div><div class=3D""><font face=3D"Courier=
" class=3D"">};</font></div><div class=3D""><br class=3D""></div><div class=
=3D"">The rest is left as an exercise. Some folks use <font face=3D"Courier=
" class=3D"">std::pair&lt; iter, iter const &gt;</font> for this purpose. I=
 wouldn=E2=80=99t.</div><div class=3D""><br class=3D""></div><br class=3D""=
><div><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=93=
09=E2=80=9304, at 7:09 PM, Arthur Tchaikovsky &lt;<a href=3D"mailto:atch.cp=
p@gmail.com" class=3D"">atch.cpp@gmail.com</a>&gt; wrote:</div><br class=3D=
"Apple-interchange-newline"><div class=3D""><div dir=3D"ltr" style=3D"font-=
family: Helvetica; font-size: 12px; font-style: normal; font-variant: norma=
l; font-weight: normal; letter-spacing: normal; line-height: normal; orphan=
s: auto; text-align: start; text-indent: 0px; text-transform: none; white-s=
pace: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0=
px;" class=3D"">No, I don't assert that it=E2=80=99s a good idea to declare=
 local variables of different types in one declaration. But what *I assert*=
 is, that it is a good idea to allow more than one type definition in for l=
oop in a sense that int and const int are two different types but it still =
allows me to compare them, so people are able to:<br class=3D"">a) write sa=
fe code<br class=3D"">b) write simple code<br class=3D"">c) compare const w=
ith non-const<br class=3D""><br class=3D""><br class=3D"">for (auto beg =3D=
 cont.cbeg(), const auto end =3D cont.cend() ; beg !=3D end; ++beg)<br clas=
s=3D"">{<br class=3D"">}<br class=3D""></div></div></blockquote></div><br c=
lass=3D""></body></html>

<p></p>

-- <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+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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_50CAB24D-56C5-4651-B58B-4B096374F8A6--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Fri, 4 Sep 2015 07:09:48 -0700 (PDT)
Raw View
------=_Part_896_1655037133.1441375788548
Content-Type: multipart/alternative;
 boundary="----=_Part_897_1813784519.1441375788548"

------=_Part_897_1813784519.1441375788548
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Friday, September 4, 2015 at 7:09:21 AM UTC-4, Arthur Tchaikovsky wrote:
>
> No, I don't assert that it=E2=80=99s a good idea to declare local variabl=
es of=20
> different types in one declaration. But what *I assert* is, that it is a=
=20
> good idea to allow more than one type definition in for loop in a sense=
=20
> that int and const int are two different types but it still allows me to=
=20
> compare them, so people are able to:
> a) write safe code
> b) write simple code
> c) compare const with non-const
>
>
> for (auto beg =3D cont.cbeg(), const auto end =3D cont.cend() ; beg !=3D =
end;=20
> ++beg)
> {
> }
>
> surely this^^^ doesn't look unreasonable?
> Is this really something unreasonable to ask for?
>

I have to agree with David's notion that this is excessively paranoid.

Without the `const`, could someone change the end iterator? Sure. Is that a=
=20
case that we need protection from?

No.

We should protect against accidental misuse of the API. However, C++ is=20
C++, so *deliberate* misuse can always happen. And I would say that it's=20
highly unlikely that someone would accidentally alter the end iterator. Oh,=
=20
it's possible. But it's also sufficiently unlikely that there's no reason=
=20
to spend precious standardization time on it.

Absolute perfect safety in every line of code is not worth achieving.

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr">On Friday, September 4, 2015 at 7:09:21 AM UTC-4, Arthur T=
chaikovsky wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">No, I don&#39;t assert that  it=E2=80=99s a good idea to declare local =
variables of different types in one declaration. But what *I assert* is, th=
at it is a good idea to allow more than one type definition in for loop in =
a sense that int and const int are two different types but it still allows =
me to compare them, so people are able to:<br>a) write safe code<br>b) writ=
e simple code<br>c) compare const with non-const<br><br><br>for (auto beg =
=3D cont.cbeg(), const auto end =3D cont.cend() ; beg !=3D end; ++beg)<br>{=
<br>}<br><br>surely this^^^ doesn&#39;t look unreasonable?<br>Is this reall=
y something unreasonable to ask for?<br></div></blockquote><div><br>I have =
to agree with David&#39;s notion that this is excessively paranoid.<br><br>=
Without the `const`, could someone change the end iterator? Sure. Is that a=
 case that we need protection from?<br><br>No.<br><br>We should protect aga=
inst accidental misuse of the API. However, C++ is C++, so <i>deliberate</i=
> misuse can always happen. And I would say that it&#39;s highly unlikely t=
hat someone would accidentally alter the end iterator. Oh, it&#39;s possibl=
e. But it&#39;s also sufficiently unlikely that there&#39;s no reason to sp=
end precious standardization time on it.<br><br>Absolute perfect safety in =
every line of code is not worth achieving.<br></div></div>

<p></p>

-- <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+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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_897_1813784519.1441375788548--
------=_Part_896_1655037133.1441375788548--

.


Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Fri, 04 Sep 2015 10:15:35 -0400
Raw View
This is a multi-part message in MIME format.
--------------000102050405090003020900
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On 2015-09-03 21:49, Klaim - Jo=C3=ABl Lamotte wrote:
> I'm assuming here that you really need access to the iterators so
> for-range-loop and for_each are not a solution?

  for (auto iter : enumerate(list)) { ... }

....and see attached for definition of 'enumerate'.

--=20
Matthew

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--------------000102050405090003020900
Content-Type: text/plain; charset=UTF-8;
 name="enumerate.h"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="enumerate.h"

Ly8gV3JpdHRlbiBieSBNYXR0aGV3IFdvZWhsa2UuIFB1YmxpYyBEb21haW4uCgp0ZW1wbGF0
ZSA8dHlwZW5hbWUgQ29udGFpbmVyPiBjbGFzcyBlbnVtZXJhdG9yCnsKcHVibGljOgogICAg
Y2xhc3MgaXRlcmF0b3I7CgogICAgZW51bWVyYXRvcihDb250YWluZXIgY29uc3QmIGNvbnRh
aW5lcikgOiBjKGNvbnRhaW5lcikge30KCiAgICBpdGVyYXRvciBiZWdpbigpIGNvbnN0IHsg
cmV0dXJuIHtjLmJlZ2luKCl9OyB9CiAgICBpdGVyYXRvciBlbmQoKSBjb25zdCB7IHJldHVy
biB7Yy5lbmQoKX07IH0KCnByb3RlY3RlZDoKICAgIENvbnRhaW5lciBjb25zdCYgYzsKfTsK
CnRlbXBsYXRlIDx0eXBlbmFtZSBDb250YWluZXI+IGNsYXNzIGVudW1lcmF0b3I8Q29udGFp
bmVyPjo6aXRlcmF0b3IKewpwdWJsaWM6CiAgICB1c2luZyBJdGVyYXRvciA9IHR5cGVuYW1l
IENvbnRhaW5lcjo6Y29uc3RfaXRlcmF0b3I7CgogICAgSXRlcmF0b3Igb3BlcmF0b3IqKCkg
Y29uc3QgeyByZXR1cm4gaTsgfQogICAgaXRlcmF0b3ImIG9wZXJhdG9yKysoKSB7ICsraTsg
cmV0dXJuICp0aGlzOyB9CgogICAgYm9vbCBvcGVyYXRvcj09KGl0ZXJhdG9yIGNvbnN0JiBv
dGhlcikgY29uc3QKICAgIHsgcmV0dXJuIGkgPT0gb3RoZXIuaTsgfQoKICAgIGJvb2wgb3Bl
cmF0b3IhPShpdGVyYXRvciBjb25zdCYgb3RoZXIpIGNvbnN0CiAgICB7IHJldHVybiBpICE9
IG90aGVyLmk7IH0KCnByb3RlY3RlZDoKICAgIGZyaWVuZCBjbGFzcyBlbnVtZXJhdG9yPENv
bnRhaW5lcj47CiAgICBpdGVyYXRvcihJdGVyYXRvciBjb25zdCYgaXRlcikgOiBpe2l0ZXJ9
IHt9CgogICAgSXRlcmF0b3IgaTsKfTsKCnRlbXBsYXRlIDx0eXBlbmFtZSBDb250YWluZXI+
CmVudW1lcmF0b3I8Q29udGFpbmVyPiBlbnVtZXJhdGUoQ29udGFpbmVyIGNvbnN0JiBjb250
YWluZXIpCnsKICAgIHJldHVybiB7Y29udGFpbmVyfTsKfQo=
--------------000102050405090003020900--


.


Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Fri, 04 Sep 2015 10:29:17 -0400
Raw View
On 2015-09-04 10:09, Nicol Bolas wrote:
> On Friday, September 4, 2015 at 7:09:21 AM UTC-4, Arthur Tchaikovsky wrote:
>> for (auto beg = cont.cbeg(), const auto end = cont.cend() ; beg != end;
>> ++beg)
>> {
>> }
>>
>> surely this^^^ doesn't look unreasonable?
>> Is this really something unreasonable to ask for?

For that purpose? IMO yes. The generic case of having multiple variables
of *genuinely different* types might be more interesting. For instance,
the recent proposal for iterating over multiple containers has something
very much like this for range-based for.

> I have to agree with David's notion that this is excessively paranoid.

TBH, I also prefer this pattern :-). Actually, I prefer to make
*everything* const that possibly can be.

That's not to say I favor Arthur's suggested change, just that I don't
find the pattern itself to be unreasonable.

> Without the `const`, could someone change the end iterator? Sure. Is
> that a case that we need protection from? [...] it's sufficiently
> unlikely that there's no reason to spend precious standardization
> time on it.

I wouldn't approach it this way, no. Adding std::enumerate (see my other
reply in this thread) would be more interesting, as it allows use of
range-based for in cases where iterators are needed (particularly if
operator* of the iterator is lossy to more than just the iterator, as in
Qt associative containers where it gives only the value but not the key
- I originally wrote that utility specifically for Qt code). It's also a
library-only change which tends to make it more palatable.

That said, I have no plans at this time for pushing that either, though
I would certainly encourage anyone wishing to do so.

--
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Arthur Tchaikovsky <atch.cpp@gmail.com>
Date: Fri, 4 Sep 2015 11:25:16 -0700 (PDT)
Raw View
------=_Part_1171_659970651.1441391116164
Content-Type: multipart/alternative;
 boundary="----=_Part_1172_1093274504.1441391116164"

------=_Part_1172_1093274504.1441391116164
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi Matthew,
That's seem like a great idea (the enumerate concept). One question though,=
=20
why enumerate as a name? Somehow doesn't correspond to what it is doing.=20
Anyway, thanks for sharing, it is really super cool.

On Friday, 4 September 2015 15:15:50 UTC+1, Matthew Woehlke wrote:
>
> On 2015-09-03 21:49, Klaim - Jo=C3=ABl Lamotte wrote:=20
> > I'm assuming here that you really need access to the iterators so=20
> > for-range-loop and for_each are not a solution?=20
>
>   for (auto iter : enumerate(list)) { ... }=20
>
> ...and see attached for definition of 'enumerate'.=20
>
> --=20
> Matthew=20
>

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr">Hi Matthew,<br>That&#39;s seem like a great idea (the enum=
erate concept). One question though, why enumerate as a name? Somehow doesn=
&#39;t correspond to what it is doing. Anyway, thanks for sharing, it is re=
ally super cool.<br><br>On Friday, 4 September 2015 15:15:50 UTC+1, Matthew=
 Woehlke  wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 2015-09-03 =
21:49, Klaim - Jo=C3=ABl Lamotte wrote:
<br>&gt; I&#39;m assuming here that you really need access to the iterators=
 so
<br>&gt; for-range-loop and for_each are not a solution?
<br>
<br>=C2=A0 for (auto iter : enumerate(list)) { ... }
<br>
<br>...and see attached for definition of &#39;enumerate&#39;.
<br>
<br>--=20
<br>Matthew
<br></blockquote></div>

<p></p>

-- <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+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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1172_1093274504.1441391116164--
------=_Part_1171_659970651.1441391116164--

.


Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Fri, 04 Sep 2015 14:41:20 -0400
Raw View
On 2015-09-04 14:25, Arthur Tchaikovsky wrote:
> That's seem like a great idea (the enumerate concept). One question thoug=
h,=20
> why enumerate as a name? Somehow doesn't correspond to what it is doing.=
=20

I forget :-). Probably because that's what it does, in the "specify each
member of a sequence individually in incrementing order"=C2=B9 sense. Also
probably loosely inspired by the Python function (though, that one is a
transform to also give you the index).

(=C2=B9 https://en.wiktionary.org/wiki/enumerate)

Of course, feel free to name it whatever you like if you use it :-).

> Anyway, thanks for sharing, it is really super cool.

Thanks.

--=20
Matthew

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.