Topic: prval and xval opperators


Author: Izzy Coding <matthew.i.greenwood@gmail.com>
Date: Tue, 6 Oct 2015 02:29:46 -0700 (PDT)
Raw View
------=_Part_153_1166573964.1444123786404
Content-Type: multipart/alternative;
 boundary="----=_Part_154_1350785951.1444123786404"

------=_Part_154_1350785951.1444123786404
Content-Type: text/plain; charset=UTF-8

Hi,

I am just wondering if we could possibly solve the issue of dangling /
invalid references from C++ by providing a dual interface for operators?

For an example consider vector<T>::operator[].

// assuming vec is a vector<int>
auto value = vec[0];    // should return a non-reference value (int)
vec[0] = 42;            // should return a reference value to use with the
right-side of the expression    (int& = 42)
auto& value = vec[0];   // this should return a reference wrapping type
that will automatically become invalid when the reference becomes invalid
                        //    (maybe by way of communication between any
non-const function calls to the underlying container type)
                        // or maybe this should be explicitly invalid code
auto&& value = vec[0];  // this should be invalid code (not sure if this is
currently possible but I don't think it should be, I may however be wrong
in that assumption)

Not sure if this makes any sense at all but I hope it is straight forward.
Just posting this to spark off some debate about this.

--

---
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_154_1350785951.1444123786404
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<br><br>I am just wondering if we could possibly solve =
the issue of dangling / invalid references from C++ by providing a dual int=
erface for operators?<br><br>For an example consider vector&lt;T&gt;::opera=
tor[].<br><br><div class=3D"prettyprint" style=3D"background-color: rgb(250=
, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-=
width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styled-by-prettif=
y">// assuming vec is a vector&lt;int&gt;</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> value </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> vec</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">[</span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">];</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0</span><s=
pan style=3D"color: #800;" class=3D"styled-by-prettify">// should return a =
non-reference value (int)</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>vec</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">[</span><span style=3D"color: #066;" class=3D"styled-by-prettif=
y">0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">]</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
066;" class=3D"styled-by-prettify">42</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span st=
yle=3D"color: #800;" class=3D"styled-by-prettify">// should return a refere=
nce value to use with the right-side of the expression =C2=A0 =C2=A0(int&am=
p; =3D 42)</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> value </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> vec</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color: #06=
6;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">];</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> =C2=A0 </span><span style=3D"color: #800;" class=3D"styled=
-by-prettify">// this should return a reference wrapping type that will aut=
omatically become invalid when the reference becomes invalid</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span=
 style=3D"color: #800;" class=3D"styled-by-prettify">// =C2=A0 =C2=A0(maybe=
 by way of communication between any non-const function calls to the underl=
ying container type)</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"style=
d-by-prettify">// or maybe this should be explicitly invalid code</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&amp;&amp;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> value </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> vec</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">[</span><span style=3D"color: #066;" class=3D"st=
yled-by-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">];</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> =C2=A0</span><span style=3D"color: #800;" class=3D"styled-by-prettify">//=
 this should be invalid code (not sure if this is currently possible but I =
don&#39;t think it should be, I may however be wrong in that assumption)</s=
pan></div></code></div><br>Not sure if this makes any sense at all but I ho=
pe it is straight forward.<br>Just posting this to spark off some debate ab=
out this.<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_154_1350785951.1444123786404--
------=_Part_153_1166573964.1444123786404--

.


Author: David Krauss <potswa@gmail.com>
Date: Tue, 6 Oct 2015 17:44:54 +0800
Raw View
--Apple-Mail=_7DCED9F2-B58A-42E5-850C-E8A16CC9125E
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9310=E2=80=9306, at 5:29 PM, Izzy Coding <matthew.i.greenwo=
od@gmail.com> wrote:
>=20
> Hi,
>=20
> I am just wondering if we could possibly solve the issue of dangling / in=
valid references from C++ by providing a dual interface for operators?
>=20
> For an example consider vector<T>::operator[].

It=E2=80=99s not clear, but it looks like you=E2=80=99re suggesting that ve=
ctor<T> should work like vector<bool>. I don=E2=80=99t see how that helps t=
o diagnose or prevent dangling references.

> Not sure if this makes any sense at all but I hope it is straight forward=
..
> Just posting this to spark off some debate about this.

Please see P0066 <http://wg21.link/p0066>. Rather than changing the types o=
f values, references, and iterators, I suggest export tags on function para=
meters (forming part of the function type, not the parameter type).

vector<T>::operator[] would be declared like this:

value_type & vector::operator[] ( size_type index ) export;

=E2=80=A6 meaning that the object =E2=80=9Cexports=E2=80=9D a self-referenc=
e to the return type.

--=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=_7DCED9F2-B58A-42E5-850C-E8A16CC9125E
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=9310=
=E2=80=9306, at 5:29 PM, Izzy Coding &lt;<a href=3D"mailto:matthew.i.greenw=
ood@gmail.com" class=3D"">matthew.i.greenwood@gmail.com</a>&gt; wrote:</div=
><br class=3D"Apple-interchange-newline"><div class=3D""><div dir=3D"ltr" c=
lass=3D"">Hi,<br class=3D""><br class=3D"">I am just wondering if we could =
possibly solve the issue of dangling / invalid references from C++ by provi=
ding a dual interface for operators?<br class=3D""><br class=3D"">For an ex=
ample consider vector&lt;T&gt;::operator[].<br class=3D""></div></div></blo=
ckquote><div><br class=3D""></div><div>It=E2=80=99s not clear, but it looks=
 like you=E2=80=99re suggesting that <font face=3D"Courier" class=3D"">vect=
or&lt;T&gt;</font> should work like <font face=3D"Courier" class=3D"">vecto=
r&lt;bool&gt;</font>. I don=E2=80=99t see how that helps to diagnose or pre=
vent dangling references.</div><br class=3D""><blockquote type=3D"cite" cla=
ss=3D""><div class=3D""><div dir=3D"ltr" class=3D"">Not sure if this makes =
any sense at all but I hope it is straight forward.<br class=3D"">Just post=
ing this to spark off some debate about this.<br class=3D""></div></div></b=
lockquote><br class=3D""></div><div>Please see&nbsp;<a href=3D"http://wg21.=
link/p0066" class=3D"">P0066</a>. Rather than changing the types of values,=
 references, and iterators, I suggest&nbsp;<span style=3D"font-family: Cour=
ier;" class=3D"">export</span>&nbsp;tags on function parameters (forming pa=
rt of the function type, not the parameter type).</div><br class=3D""><div =
class=3D""><font face=3D"Courier" class=3D"">vector&lt;T&gt;::operator[]</f=
ont> would be declared like this:</div><div class=3D""><br class=3D""></div=
><div class=3D""><font face=3D"Courier" class=3D"">value_type &amp; vector:=
:operator[] ( size_type index ) export;</font></div><div class=3D""><br cla=
ss=3D""></div><div class=3D"">=E2=80=A6 meaning that the object =E2=80=9Cex=
ports=E2=80=9D a self-reference to the return type.</div><div class=3D""><b=
r class=3D""></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=_7DCED9F2-B58A-42E5-850C-E8A16CC9125E--

.


Author: Izzy Coding <matthew.i.greenwood@gmail.com>
Date: Tue, 6 Oct 2015 07:49:24 -0700 (PDT)
Raw View
------=_Part_2923_895277649.1444142964112
Content-Type: multipart/alternative;
 boundary="----=_Part_2924_1672132416.1444142964112"

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


>
>
> It=E2=80=99s not clear, but it looks like you=E2=80=99re suggesting that =
vector<T> should=20
> work like vector<bool>. I don=E2=80=99t see how that helps to diagnose or=
 prevent=20
> dangling references.
>
>
Not at all, I am just suggesting that maybe we should make it a rule in the=
=20
standard that we cannot take a reference from an operator and assign it to=
=20
a reference typed variable.
This then would mean we could not get trapped in the following situations=
=20
and would avoid invalid iterators:

auto& var =3D vec[0];
vec.push_back(24);
var =3D 42;

Another possibility would be to provide a custom operator that allows you=
=20
to return differing types than the current version (however this would=20
require a change to make the return type a defining part of the functions=
=20
signature and thus would allow overloading on return type):

template< typename T >
class Things
{
public:
    T& operator[] (size_t n) { ... }                // Normal indexing=20
operator
    Other<T> operator[] (size_t n) { ... }      // New operator to allow=20
non-referenced indexing (this would effectively return a copy of the=20
indexed item so that it can never be out of scope)
};

This extension would then allow for the developer to create an indexing=20
operator to return a protected reference for lazy evaluations. But this=20
would solve the dangling reference issue.


Please see P0066 <http://wg21.link/p0066>. Rather than changing the types=
=20
> of values, references, and iterators, I suggest export tags on function=
=20
> parameters (forming part of the function type, not the parameter type).
> =20
>
vector<T>::operator[] would be declared like this:
>
> value_type & vector::operator[] ( size_type index ) export;
>
> =E2=80=A6 meaning that the object =E2=80=9Cexports=E2=80=9D a self-refere=
nce to the return type.
>
>
The reason I would not suggest this change is because it ultimately adds a=
=20
new keyword to the language and from my experience this seems too much of=
=20
an issue to get done. Hence I only suggested the change of definitions=20
rather than adding a new language syntax.

I hope this clears up what I was trying to say a little bit.

--=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_2924_1672132416.1444142964112
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D=
"word-wrap:break-word"><div><div><br></div><div>It=E2=80=99s not clear, but=
 it looks like you=E2=80=99re suggesting that <font face=3D"Courier">vector=
&lt;T&gt;</font> should work like <font face=3D"Courier">vector&lt;bool&gt;=
</font>. I don=E2=80=99t see how that helps to diagnose or prevent dangling=
 references.</div><br></div></div></blockquote><div><br>Not at all, I am ju=
st suggesting that maybe we should make it a rule in the standard that we c=
annot take a reference from an operator and assign it to a reference typed =
variable.<br>This then would mean we could not get trapped in the following=
 situations and would avoid invalid iterators:<br><br><div class=3D"prettyp=
rint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187,=
 187, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"=
><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">var</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> vec</span><span style=3D"color: #660;" class=3D"styled-by-prettify">[</sp=
an><span style=3D"color: #066;" class=3D"styled-by-prettify">0</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">];</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br>vec</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">push_back</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">24</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">var</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">42</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">;</span></div></code></div><br>Anoth=
er possibility would be to provide a custom operator that allows you to ret=
urn differing types than the current version (however this would require a =
change to make the return type a defining part of the functions signature a=
nd thus would allow overloading on return type):<br><br><div class=3D"prett=
yprint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(18=
7, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-word=
;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D=
"color: #008;" class=3D"styled-by-prettify">template</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> T </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Things</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">public</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 T</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">operator</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">[]</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">si=
ze_t n</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">...</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</span><s=
pan style=3D"color: #800;" class=3D"styled-by-prettify">// Normal indexing =
operator</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r>=C2=A0 =C2=A0 </span><span style=3D"color: #606;" class=3D"styled-by-pret=
tify">Other</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">[]</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">size_t n</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">...</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0</span><span style=3D=
"color: #800;" class=3D"styled-by-prettify">// New operator to allow non-re=
ferenced indexing (this would effectively return a copy of the indexed item=
 so that it can never be out of scope)</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">};</span></div></code></div><br>This extension woul=
d then allow for the developer to create an indexing operator to return a p=
rotected reference for lazy evaluations. But this would solve the dangling =
reference issue.<br><br><br></div><blockquote class=3D"gmail_quote" style=
=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: =
1ex;"><div><div>Please see=C2=A0<a href=3D"http://wg21.link/p0066" target=
=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.goo=
gle.com/url?q\75http%3A%2F%2Fwg21.link%2Fp0066\46sa\75D\46sntz\0751\46usg\7=
5AFQjCNFqR-kO6K1rJDHyR92XjldpetuVtQ&#39;;return true;" onclick=3D"this.href=
=3D&#39;http://www.google.com/url?q\75http%3A%2F%2Fwg21.link%2Fp0066\46sa\7=
5D\46sntz\0751\46usg\75AFQjCNFqR-kO6K1rJDHyR92XjldpetuVtQ&#39;;return true;=
">P0066</a>. Rather than changing the types of values, references, and iter=
ators, I suggest=C2=A0<span style=3D"font-family:Courier">export</span>=C2=
=A0tags on function parameters (forming part of the function type, not the =
parameter type).</div>=C2=A0</div></blockquote><blockquote class=3D"gmail_q=
uote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pad=
ding-left: 1ex;"><div style=3D"word-wrap:break-word"><div><font face=3D"Cou=
rier">vector&lt;T&gt;::operator[]</font> would be declared like this:</div>=
<div><br></div><div><font face=3D"Courier">value_type &amp; vector::operato=
r[] ( size_type index ) export;</font></div><div><br></div><div>=E2=80=A6 m=
eaning that the object =E2=80=9Cexports=E2=80=9D a self-reference to the re=
turn type.</div><div><br></div></div></blockquote><div><br>The reason I wou=
ld not suggest this change is because it ultimately adds a new keyword to t=
he language and from my experience this seems too much of an issue to get d=
one. Hence I only suggested the change of definitions rather than adding a =
new language syntax.<br><br>I hope this clears up what I was trying to say =
a little bit.<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_2924_1672132416.1444142964112--
------=_Part_2923_895277649.1444142964112--

.


Author: Izzy Coding <matthew.i.greenwood@gmail.com>
Date: Tue, 6 Oct 2015 07:51:27 -0700 (PDT)
Raw View
------=_Part_575_421654251.1444143087821
Content-Type: multipart/alternative;
 boundary="----=_Part_576_1134650055.1444143087821"

------=_Part_576_1134650055.1444143087821
Content-Type: text/plain; charset=UTF-8



> This then would mean we could not get trapped in the following situations
>> and would avoid invalid *iterators*:
>>
>>
I meant references not iterators

--

---
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_576_1134650055.1444143087821
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><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"><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.=
8ex;border-left:1px #ccc solid;padding-left:1ex"><div style=3D"word-wrap:br=
eak-word"><div>This then would mean we could not get trapped in the followi=
ng situations and would avoid invalid <b>iterators</b>:<br><br></div></div>=
</blockquote></div></blockquote><div>=C2=A0<br>I meant references not itera=
tors</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_576_1134650055.1444143087821--
------=_Part_575_421654251.1444143087821--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 6 Oct 2015 08:12:16 -0700 (PDT)
Raw View
------=_Part_339_1941482206.1444144336804
Content-Type: multipart/alternative;
 boundary="----=_Part_340_769352088.1444144336804"

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

On Tuesday, October 6, 2015 at 10:49:24 AM UTC-4, Izzy Coding wrote:
>
>
>> It=E2=80=99s not clear, but it looks like you=E2=80=99re suggesting that=
 vector<T>=20
>> should work like vector<bool>. I don=E2=80=99t see how that helps to dia=
gnose or=20
>> prevent dangling references.
>>
>>
> Not at all, I am just suggesting that maybe we should make it a rule in=
=20
> the standard that we cannot take a reference from an operator and assign =
it=20
> to a reference typed variable.
>

.... have you considered the ramifications of this?

Like this:

for(auto &x : vec)

That involves the use of `operator*`, as applied to the iterators of `vec`.=
=20
It's overloaded on iterators, and it returns a reference.

One that you now have to copy. Congratulations, you just broke like 50% of=
=20
people who use range-based for loops.

That's what we would call a "non-starter".
=20

> Please see P0066 <http://wg21.link/p0066>. Rather than changing the types=
=20
>> of values, references, and iterators, I suggest export tags on function=
=20
>> parameters (forming part of the function type, not the parameter type).
>> =20
>>
> vector<T>::operator[] would be declared like this:
>>
>> value_type & vector::operator[] ( size_type index ) export;
>>
>> =E2=80=A6 meaning that the object =E2=80=9Cexports=E2=80=9D a self-refer=
ence to the return type.
>>
>>
> The reason I would not suggest this change is because it ultimately adds =
a=20
> new keyword to the language and from my experience this seems too much of=
=20
> an issue to get done.
>

Um, export is *already* a keyword. Granted since C++11 it is without any=20
meaning (which is why it's available for P0066). But it's still a keyword.

Also, P0056 is aimed at making new keywords less problematic.

--=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_340_769352088.1444144336804
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tuesday, October 6, 2015 at 10:49:24 AM UTC-4, Izzy Cod=
ing 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"><bl=
ockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div style=3D"word-wrap:break-word"><d=
iv><div><br></div><div>It=E2=80=99s not clear, but it looks like you=E2=80=
=99re suggesting that <font face=3D"Courier">vector&lt;T&gt;</font> should =
work like <font face=3D"Courier">vector&lt;bool&gt;</font>. I don=E2=80=99t=
 see how that helps to diagnose or prevent dangling references.</div><br></=
div></div></blockquote><div><br>Not at all, I am just suggesting that maybe=
 we should make it a rule in the standard that we cannot take a reference f=
rom an operator and assign it to a reference typed variable.<br></div></div=
></blockquote><div><br>... have you considered the ramifications of this?<b=
r><br>Like this:<br><br><div class=3D"prettyprint" style=3D"background-colo=
r: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: soli=
d; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">for</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">x </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> vec</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">)</span></div></code></div><br>That involves th=
e use of `operator*`, as applied to the iterators of `vec`. It&#39;s overlo=
aded on iterators, and it returns a reference.<br><br>One that you now have=
 to copy. Congratulations, you just broke like 50% of people who use range-=
based for loops.<br><br>That&#39;s what we would call a &quot;non-starter&q=
uot;.<br>=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></div><blockquote class=3D"gmail_quote" style=3D"margin:0;mar=
gin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>Pleas=
e see=C2=A0<a href=3D"http://wg21.link/p0066" rel=3D"nofollow" target=3D"_b=
lank" onmousedown=3D"this.href=3D&#39;http://www.google.com/url?q\75http%3A=
%2F%2Fwg21.link%2Fp0066\46sa\75D\46sntz\0751\46usg\75AFQjCNFqR-kO6K1rJDHyR9=
2XjldpetuVtQ&#39;;return true;" onclick=3D"this.href=3D&#39;http://www.goog=
le.com/url?q\75http%3A%2F%2Fwg21.link%2Fp0066\46sa\75D\46sntz\0751\46usg\75=
AFQjCNFqR-kO6K1rJDHyR92XjldpetuVtQ&#39;;return true;">P0066</a>. Rather tha=
n changing the types of values, references, and iterators, I suggest=C2=A0<=
span style=3D"font-family:Courier">export</span>=C2=A0tags on function para=
meters (forming part of the function type, not the parameter type).</div>=
=C2=A0</div></blockquote><blockquote class=3D"gmail_quote" style=3D"margin:=
0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div style=
=3D"word-wrap:break-word"><div><font face=3D"Courier">vector&lt;T&gt;::oper=
ator[]</font> would be declared like this:</div><div><br></div><div><font f=
ace=3D"Courier">value_type &amp; vector::operator[] ( size_type index ) exp=
ort;</font></div><div><br></div><div>=E2=80=A6 meaning that the object =E2=
=80=9Cexports=E2=80=9D a self-reference to the return type.</div><div><br><=
/div></div></blockquote><div><br>The reason I would not suggest this change=
 is because it ultimately adds a new keyword to the language and from my ex=
perience this seems too much of an issue to get done.</div></div></blockquo=
te><div><br>Um, export is <i>already</i> a keyword. Granted since C++11 it =
is without any meaning (which is why it&#39;s available for P0066). But it&=
#39;s still a keyword.<br><br>Also, P0056 is aimed at making new keywords l=
ess problematic.<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_340_769352088.1444144336804--
------=_Part_339_1941482206.1444144336804--

.


Author: David Krauss <potswa@gmail.com>
Date: Tue, 6 Oct 2015 23:52:48 +0800
Raw View
--Apple-Mail=_B64F253F-B2B0-4A89-852D-9396DD3DE32E
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9310=E2=80=9306, at 10:49 PM, Izzy Coding <matthew.i.greenw=
ood@gmail.com> wrote:
>=20
>=20
> It=E2=80=99s not clear, but it looks like you=E2=80=99re suggesting that =
vector<T> should work like vector<bool>. I don=E2=80=99t see how that helps=
 to diagnose or prevent dangling references.
>=20
>=20
> Not at all, I am just suggesting that maybe we should make it a rule in t=
he standard that we cannot take a reference from an operator and assign it =
to a reference typed variable.

You mean like this? http://coliru.stacked-crooked.com/a/3dcfb8a8221b8058 <h=
ttp://coliru.stacked-crooked.com/a/3dcfb8a8221b8058>
> This then would mean we could not get trapped in the following situations=
 and would avoid invalid iterators:
>=20
> auto& var =3D vec[0];
> vec.push_back(24);
> var =3D 42;

Keeping a reference into a container is pretty common. There=E2=80=99s stro=
ng motivation to make it safer, not illegal. See Herb Sutter=E2=80=99s rece=
nt CppCon presentation on lifetime analysis.

> Another possibility would be to provide a custom operator that allows you=
 to return differing types than the current version (however this would req=
uire a change to make the return type a defining part of the functions sign=
ature and thus would allow overloading on return type):
>=20
> template< typename T >
> class Things
> {
> public:
>     T& operator[] (size_t n) { ... }                // Normal indexing op=
erator
>     Other<T> operator[] (size_t n) { ... }      // New operator to allow =
non-referenced indexing (this would effectively return a copy of the indexe=
d item so that it can never be out of scope)
> };
>=20
> This extension would then allow for the developer to create an indexing o=
perator to return a protected reference for lazy evaluations. But this woul=
d solve the dangling reference issue.

This would make the language much more complicated. How does it know which =
one to call? The return-by-reference overload exists, but it=E2=80=99s not =
allowed to bind to a named reference? What about auto & var =3D vec[0] =3D =
vec[0];? In this case operator[] is at the mercy of the return type of oper=
ator=3D.

Returning a copy means returning a temporary, which goes out of scope soone=
r than anything. That seems to be the solution to a different problem than =
the stated one. Already we can overload on the && ref-qualifier and return =
by value instead of reference, but there=E2=80=99s no good universal policy=
 for which to use when=E2=80=A6 it=E2=80=99s a safety vs. efficiency tradeo=
ff. That was a big chunk of the initial motivation for N4221/P0066, hence i=
ts focus on accessor functions.

You=E2=80=99ve described what you want to prevent, but so far no way to pre=
vent it.

> The reason I would not suggest this change is because it ultimately adds =
a new keyword to the language and from my experience this seems too much of=
 an issue to get done. Hence I only suggested the change of definitions rat=
her than adding a new language syntax.

It=E2=80=99s a big proposal; the keyword is only the start. Stroustrup has =
recommended being less conservative about keywords, IIRC, for C++17. The fi=
rst priority is clean semantics, the second priority is clean syntax, and p=
reserving old variable names is third (as long as programs don=E2=80=99t su=
rprisingly change meaning). export isn=E2=80=99t a new keyword, but it coul=
d end up called something else.

--=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=_B64F253F-B2B0-4A89-852D-9396DD3DE32E
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=9310=
=E2=80=9306, at 10:49 PM, Izzy Coding &lt;<a href=3D"mailto:matthew.i.green=
wood@gmail.com" class=3D"">matthew.i.greenwood@gmail.com</a>&gt; wrote:</di=
v><br class=3D"Apple-interchange-newline"><div class=3D""><div dir=3D"ltr" =
class=3D""><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left=
: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-=
wrap:break-word" class=3D""><div class=3D""><div class=3D""><br class=3D"">=
</div><div class=3D"">It=E2=80=99s not clear, but it looks like you=E2=80=
=99re suggesting that <font face=3D"Courier" class=3D"">vector&lt;T&gt;</fo=
nt> should work like <font face=3D"Courier" class=3D"">vector&lt;bool&gt;</=
font>. I don=E2=80=99t see how that helps to diagnose or prevent dangling r=
eferences.</div><br class=3D""></div></div></blockquote><div class=3D""><br=
 class=3D"">Not at all, I am just suggesting that maybe we should make it a=
 rule in the standard that we cannot take a reference from an operator and =
assign it to a reference typed variable.<br class=3D""></div></div></div></=
blockquote><div><br class=3D""></div><div>You mean like this?&nbsp;<a href=
=3D"http://coliru.stacked-crooked.com/a/3dcfb8a8221b8058" class=3D"">http:/=
/coliru.stacked-crooked.com/a/3dcfb8a8221b8058</a></div><br class=3D""><blo=
ckquote type=3D"cite" class=3D""><div class=3D""><div dir=3D"ltr" class=3D"=
"><div class=3D"">This then would mean we could not get trapped in the foll=
owing situations and would avoid invalid iterators:<br class=3D""><br class=
=3D""><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 2=
50); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1=
px; word-wrap: break-word;"><code class=3D"prettyprint"><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&amp;</span> <span style=3D"color: #008;" =
class=3D"styled-by-prettify">var</span> <span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span> vec<span style=3D"color: #660;" class=3D=
"styled-by-prettify">[</span><span style=3D"color: #066;" class=3D"styled-b=
y-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">];</span><br class=3D"">vec<span style=3D"color: #660;" class=3D"styled-=
by-prettify">.</span>push_back<span style=3D"color: #660;" class=3D"styled-=
by-prettify">(</span><span style=3D"color: #066;" class=3D"styled-by-pretti=
fy">24</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</=
span><br class=3D""><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">var</span> <span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</span> <span style=3D"color: #066;" class=3D"styled-by-prettify">42</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></code></=
div></div></div></div></blockquote><div><br class=3D""></div><div>Keeping a=
 reference into a container is pretty common. There=E2=80=99s strong motiva=
tion to make it safer, not illegal. See Herb Sutter=E2=80=99s recent CppCon=
 presentation on lifetime analysis.</div><br class=3D""><blockquote type=3D=
"cite" class=3D""><div class=3D""><div dir=3D"ltr" class=3D""><div class=3D=
"">Another possibility would be to provide a custom operator that allows yo=
u to return differing types than the current version (however this would re=
quire a change to make the return type a defining part of the functions sig=
nature and thus would allow overloading on return type):<br class=3D""></di=
v></div></div></blockquote><div><blockquote type=3D"cite" class=3D""><br cl=
ass=3D""></blockquote></div><blockquote type=3D"cite" class=3D""><div class=
=3D""><div dir=3D"ltr" class=3D""><div class=3D""><div class=3D"prettyprint=
" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187=
, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><co=
de class=3D"prettyprint"><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">template</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&lt;</span> <span style=3D"color: #008;" class=3D"styled-by-prettify"=
>typename</span> T <span style=3D"color: #660;" class=3D"styled-by-prettify=
">&gt;</span><br class=3D""><span style=3D"color: #008;" class=3D"styled-by=
-prettify">class</span> <span style=3D"color: #606;" class=3D"styled-by-pre=
ttify">Things</span><br class=3D""><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">{</span><br class=3D""><span style=3D"color: #008;" class=
=3D"styled-by-prettify">public</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">:</span><br class=3D"">&nbsp; &nbsp; T<span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&amp;</span> <span style=3D"color:=
 #008;" class=3D"styled-by-prettify">operator</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">[]</span> <span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(</span>size_t n<span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">)</span> <span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{</span> <span style=3D"color: #660;" class=3D"styled-by=
-prettify">...</span> <span style=3D"color: #660;" class=3D"styled-by-prett=
ify">}</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span =
style=3D"color: #800;" class=3D"styled-by-prettify">// Normal indexing oper=
ator</span><br class=3D"">&nbsp; &nbsp; <span style=3D"color: #606;" class=
=3D"styled-by-prettify">Other</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">&lt;</span>T<span style=3D"color: #660;" class=3D"styled=
-by-prettify">&gt;</span> <span style=3D"color: #008;" class=3D"styled-by-p=
rettify">operator</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">[]</span> <span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span>size_t n<span style=3D"color: #660;" class=3D"styled-by-prettify">)=
</span> <span style=3D"color: #660;" class=3D"styled-by-prettify">{</span> =
<span style=3D"color: #660;" class=3D"styled-by-prettify">...</span> <span =
style=3D"color: #660;" class=3D"styled-by-prettify">}</span> &nbsp; &nbsp; =
&nbsp;<span style=3D"color: #800;" class=3D"styled-by-prettify">// New oper=
ator to allow non-referenced indexing (this would effectively return a copy=
 of the indexed item so that it can never be out of scope)</span><br class=
=3D""><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span></=
code></div><br class=3D"">This extension would then allow for the developer=
 to create an indexing operator to return a protected reference for lazy ev=
aluations. But this would solve the dangling reference issue.<br class=3D""=
></div></div></div></blockquote><div><br class=3D""></div><div>This would m=
ake the language much more complicated. How does it know which one to call?=
 The return-by-reference overload exists, but it=E2=80=99s not allowed to b=
ind to a named reference? What about <font face=3D"Courier" class=3D"">auto=
 &amp; var =3D vec[0] =3D vec[0];</font>? In this case&nbsp;<font face=3D"C=
ourier" class=3D"">operator[]</font> is at the mercy of the return type of&=
nbsp;<font face=3D"Courier" class=3D"">operator=3D</font>.</div><div><br cl=
ass=3D""></div><div>Returning a copy means returning a temporary, which goe=
s out of scope sooner than anything. That seems to be the solution to a dif=
ferent problem than the stated one. Already we can overload on the <font fa=
ce=3D"Courier" class=3D"">&amp;&amp;</font> ref-qualifier and return by val=
ue instead of reference, but there=E2=80=99s no good universal policy for w=
hich to use when=E2=80=A6 it=E2=80=99s a safety vs. efficiency tradeoff. Th=
at was a big chunk of the initial motivation for N4221/P0066, hence its foc=
us on accessor functions.</div><div class=3D""><br class=3D""></div><div cl=
ass=3D"">You=E2=80=99ve described what you want to prevent, but so far no w=
ay to prevent it.</div><div class=3D""><br class=3D""></div><blockquote typ=
e=3D"cite" class=3D""><div class=3D""><div dir=3D"ltr" class=3D""><div clas=
s=3D"">The reason I would not suggest this change is because it ultimately =
adds a new keyword to the language and from my experience this seems too mu=
ch of an issue to get done. Hence I only suggested the change of definition=
s rather than adding a new language syntax.</div></div></div></blockquote><=
/div><br class=3D""><div class=3D"">It=E2=80=99s a big proposal; the keywor=
d is only the start. Stroustrup has recommended being less conservative abo=
ut keywords, IIRC, for C++17. The first priority is clean semantics, the se=
cond priority is clean syntax, and preserving old variable names is third (=
as long as programs don=E2=80=99t surprisingly change meaning). <font face=
=3D"Courier" class=3D"">export</font> isn=E2=80=99t a new keyword, but it c=
ould end up called something else.</div><div class=3D""><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=_B64F253F-B2B0-4A89-852D-9396DD3DE32E--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 6 Oct 2015 19:03:46 +0300
Raw View
On 6 October 2015 at 18:52, David Krauss <potswa@gmail.com> wrote:
> It=E2=80=99s a big proposal; the keyword is only the start. Stroustrup ha=
s
> recommended being less conservative about keywords, IIRC, for C++17. The

o_O what is this referring to?

> first priority is clean semantics, the second priority is clean syntax, a=
nd
> preserving old variable names is third (as long as programs don=E2=80=99t

Whose priorities are these?

--=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/.

.


Author: David Krauss <potswa@gmail.com>
Date: Wed, 7 Oct 2015 08:44:13 +0800
Raw View
--Apple-Mail=_A0774A2E-F3DC-4160-AC44-C830C70F0442
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9310=E2=80=9307, at 12:03 AM, Ville Voutilainen <ville.vout=
ilainen@gmail.com> wrote:
>=20
> On 6 October 2015 at 18:52, David Krauss <potswa@gmail.com> wrote:
>> It=E2=80=99s a big proposal; the keyword is only the start. Stroustrup h=
as
>> recommended being less conservative about keywords, IIRC, for C++17. The
>=20
> o_O what is this referring to?

Hmm, in N4492, the best I can find is: [Don=E2=80=99t] =E2=80=9CMake someth=
ing a library because that's easier to get accepted in the committee than a=
 language feature (even if there is good argument that what is provided is =
fundamental)=E2=80=9D =E2=80=94 this relates to coroutines and the yield/aw=
ait keywords. Or [don=E2=80=99t] =E2=80=9CThink that =E2=80=9Cno keywords=
=E2=80=9D implies simplicity and usability.=E2=80=9D

>> first priority is clean semantics, the second priority is clean syntax, =
and
>> preserving old variable names is third (as long as programs don=E2=80=99=
t
>=20
> Whose priorities are these?

At worst, just mine. I could just be adding my own reasoning to my own perc=
eption that hostility to new keywords is dropping somewhat. Still, at least=
 in this thread, I=E2=80=99d rather see some discernible semantics. The pro=
posal doesn=E2=80=99t yet solve the problem, so it=E2=80=99s premature to s=
ay that the solution without new syntax is better.

--=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=_A0774A2E-F3DC-4160-AC44-C830C70F0442
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=9310=
=E2=80=9307, at 12:03 AM, Ville Voutilainen &lt;<a href=3D"mailto:ville.vou=
tilainen@gmail.com" class=3D"">ville.voutilainen@gmail.com</a>&gt; wrote:</=
div><br class=3D"Apple-interchange-newline"><div class=3D"">On 6 October 20=
15 at 18:52, David Krauss &lt;<a href=3D"mailto:potswa@gmail.com" class=3D"=
">potswa@gmail.com</a>&gt; wrote:<br class=3D""><blockquote type=3D"cite" c=
lass=3D"">It=E2=80=99s a big proposal; the keyword is only the start. Strou=
strup has<br class=3D"">recommended being less conservative about keywords,=
 IIRC, for C++17. The<br class=3D""></blockquote><br class=3D"">o_O what is=
 this referring to?<br class=3D""></div></blockquote><div><br class=3D""></=
div><div>Hmm, in N4492, the best I can find is: [Don=E2=80=99t] =E2=80=9CMa=
ke something a library because that's easier to get accepted in the committ=
ee than a language feature (even if there is good argument that what is pro=
vided is fundamental)=E2=80=9D =E2=80=94 this relates to coroutines and the=
 <font face=3D"Courier" class=3D"">yield</font>/<font face=3D"Courier" clas=
s=3D"">await</font> keywords. Or [don=E2=80=99t] =E2=80=9CThink that =E2=80=
=9Cno keywords=E2=80=9D implies simplicity and usability.=E2=80=9D</div><di=
v><br class=3D""></div><blockquote type=3D"cite" class=3D""><div class=3D""=
><blockquote type=3D"cite" class=3D"">first priority is clean semantics, th=
e second priority is clean syntax, and<br class=3D"">preserving old variabl=
e names is third (as long as programs don=E2=80=99t<br class=3D""></blockqu=
ote><br class=3D"">Whose priorities are these?<br class=3D""></div></blockq=
uote></div><br class=3D""><div class=3D"">At worst, just mine. I could just=
 be adding my own reasoning to my own perception that hostility to new keyw=
ords is dropping somewhat. Still, at least in this thread, I=E2=80=99d rath=
er see some discernible semantics. The proposal doesn=E2=80=99t yet solve t=
he problem, so it=E2=80=99s premature to say that the solution without new =
syntax is better.</div><div class=3D""><br class=3D""></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=_A0774A2E-F3DC-4160-AC44-C830C70F0442--

.