Topic: auto<...> for benefit of changing container without
Author: i59developer@gmail.com
Date: Mon, 28 Aug 2017 13:31:45 -0700 (PDT)
Raw View
------=_Part_7356_183118434.1503952305853
Content-Type: multipart/alternative;
boundary="----=_Part_7357_1012349936.1503952305854"
------=_Part_7357_1012349936.1503952305854
Content-Type: text/plain; charset="UTF-8"
Basic example of the proposed feature:
std::vector<int>& get_numbers();
auto<int>& numbers = get_numbers();
The idea behind this is to allow explicitly defining what template
arguments you are expecting from the right-hand side, without requiring a
specific implementation. This would give the benefits of auto in providing
the means for replacing say a container, without losing the ability to see
what we are operating on (in this case an integer).
This is especially useful for containers, see the difference:
std::vector<int>& numbers = get_numbers();
auto& numbers = get_numbers();
auto<int>& numbers = get_numbers();
If you wanted, you could even use it as:
auto<int>::iterator myiter = numbers.begin();
... which would be equivalent to:
decltype(numbers)::iterator myiter = numbers.begin();
auto myiter = numbers.begin();
std::vector<int>::iterator myiter = numbers.begin();
Quality of life proposal for the most part, aimed at bridging the gap
between the "auto is unclear" and "auto is great for refactoring" camps.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/7aa0682c-8e05-4748-a38b-c747465edd96%40isocpp.org.
------=_Part_7357_1012349936.1503952305854
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Basic example of the proposed feature:<br><div class=3D"pr=
ettyprint" style=3D"border-color: rgb(187, 187, 187); border-style: solid; =
border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint" styl=
e=3D""><div class=3D"subprettyprint" style=3D""><span style=3D"color: #000;=
" class=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">vector</span><span style=3D"color: #080;" class=3D"styled-b=
y-prettify"><int></span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> get_numbers</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>auto</span><span style=3D"color: #080;" class=3D"styled-by-prettify"><<=
/span><font color=3D"#000000"><span style=3D"color: #080;" class=3D"styled-=
by-prettify">int</span></font><span style=3D"color: #080;" class=3D"styled-=
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=
"> numbers </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>=3D</span><span style=3D"background-color: rgb(250, 250, 250);"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span></span><span style=
=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">get_numbers</span></span><font face=3D"Arial, Helvetica, sans-seri=
f"><span style=3D"background-color: rgb(255, 255, 255);"><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">()</span></span></font><font color=
=3D"#000000" style=3D"background-color: rgb(250, 250, 250);"><span style=3D=
"color: #660;" class=3D"styled-by-prettify">;</span></font></div></code></d=
iv><br><div>The idea behind this is to allow explicitly defining what templ=
ate arguments you are expecting from the right-hand side, without requiring=
a specific implementation. This would give the benefits of auto in providi=
ng the means for replacing say a container, without losing the ability to s=
ee what we are operating on (in this case an integer).</div><div><br></div>=
<div>This is especially useful for containers, see the difference:</div><di=
v><br></div><div><div class=3D"prettyprint" style=3D"background-color: rgb(=
250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bord=
er-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div cla=
ss=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">vector</sp=
an><span style=3D"color: #080;" class=3D"styled-by-prettify"><int></s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> numbers </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><font col=
or=3D"#000000"><span style=3D"color: #000;" class=3D"styled-by-prettify"> g=
et_numbers</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
();</span></font></div></code></div><br><div class=3D"prettyprint" style=3D=
"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); bo=
rder-style: solid; border-width: 1px; word-wrap: break-word;"><code class=
=3D"prettyprint"><div class=3D"subprettyprint"><font color=3D"#000000"><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">auto</span></font><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> numbers </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><font color=3D"#=
000000"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
/font><span style=3D"color: #000;" class=3D"styled-by-prettify">get_numbers=
</span><font color=3D"#000000"><span style=3D"color: #660;" class=3D"styled=
-by-prettify">();</span></font><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br></span></div></code></div><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"><font color=3D"#000000=
" style=3D"font-family: Arial, Helvetica, sans-serif;"><span style=3D"color=
: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #080=
;" class=3D"styled-by-prettify"><int></span></font><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> numbers </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">=3D</span><font color=3D"#000000" style=
=3D"font-family: Arial, Helvetica, sans-serif;"><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span></font><span style=3D"color: #000;" =
class=3D"styled-by-prettify">get_numbers</span><font color=3D"#000000" styl=
e=3D"font-family: Arial, Helvetica, sans-serif;"><span style=3D"color: #660=
;" class=3D"styled-by-prettify">();</span></font><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span></div></code></div><br>If you wa=
nted, you could even use it as:</div><div><br></div><div><div class=3D"pret=
typrint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(1=
87, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-wor=
d;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><font color=
=3D"#000000" style=3D"font-family: Arial, Helvetica, sans-serif;"><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"=
color: #080;" class=3D"styled-by-prettify"><int></span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">iterator</span></font><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: rgb(=
0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-by-prettify">myiter=
</span></span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> number=
s</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">begin</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></di=
v><br>.. which would be equivalent to:</div><div><br></div><div><div class=
=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-colo=
r: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: b=
reak-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><font=
color=3D"#000088" face=3D"Arial, Helvetica, sans-serif"><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">decltype</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">numbers</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">)::</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">iterator </span></font><span style=3D"color: rgb(0, 0, 0=
);"><span style=3D"color: #000;" class=3D"styled-by-prettify">myiter </span=
></span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> numbers</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">begin</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br></span></div></code></div></div><di=
v><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"subpretty=
print"><font color=3D"#000088" face=3D"Arial, Helvetica, sans-serif"><span =
style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span></font><span style=
=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">myiter </span></span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> numbers</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">.</span><span style=3D"color: #008;" class=3D"styled-by-prettify">begin=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div>=
</code></div><div class=3D"prettyprint" style=3D"background-color: rgb(250,=
250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-w=
idth: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><font color=3D"#000088" face=3D"Arial, Helvetica, sans-=
serif"><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">vector</span><span style=
=3D"color: #080;" class=3D"styled-by-prettify"><int></span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">iterator </span></font><span style=
=3D"color: #000;" class=3D"styled-by-prettify">myiter </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> numbers</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">begin</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br></span></div></code></div><br></div><div>=C2=A0Quality of=
life proposal for the most part, aimed at bridging the gap between the &qu=
ot;auto is unclear" and "auto is great for refactoring" camp=
s.</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7aa0682c-8e05-4748-a38b-c747465edd96%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7aa0682c-8e05-4748-a38b-c747465edd96=
%40isocpp.org</a>.<br />
------=_Part_7357_1012349936.1503952305854--
------=_Part_7356_183118434.1503952305853--
.