Topic: auto<...> for benefit of changing container
Author: Andrey Semashev <andrey.semashev@gmail.com>
Date: Tue, 29 Aug 2017 02:41:29 +0300
Raw View
On 08/28/17 23:31, i59developer@gmail.com wrote:
> 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).
IMHO, this feature doesn't look compelling enough. I think one of the
main selling points of auto was not having to type the long typenames,
especially of iterators, especially in templated code. So instead of
typename std::vector<T>::iterator it = c.begin();
you could write
auto it = c.begin();
With your proposal, you don't really save much:
typename auto<T>::iterator it = c.begin();
I mean, it's 11 characters vs. 4 (7 characters saved), but the whole
typename is still 26. So the gain is questionable, and the use case
where I'd be inclined to spell out the type like that is hard to imagine.
On the other hand, this might be problematic to implement because a
template id is expected before '<', which auto is not. You would need to
change the grammar for this to work.
--
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/3796e4db-2227-8d38-2e36-f3dace1deffc%40gmail.com.
.
Author: Ricardo Fabiano de Andrade <ricardofabianodeandrade@gmail.com>
Date: Tue, 29 Aug 2017 03:04:53 +0000
Raw View
--001a1140b9ac8a4d4e0557dbad39
Content-Type: text/plain; charset="UTF-8"
On Mon, Aug 28, 2017 at 6:41 PM Andrey Semashev <andrey.semashev@gmail.com>
wrote:
> On 08/28/17 23:31, i59developer@gmail.com wrote:
> > 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).
>
> IMHO, this feature doesn't look compelling enough. I think one of the
> main selling points of auto was not having to type the long typenames,
> especially of iterators, especially in templated code. So instead of
>
> typename std::vector<T>::iterator it = c.begin();
>
> you could write
>
> auto it = c.begin();
>
> With your proposal, you don't really save much:
>
> typename auto<T>::iterator it = c.begin();
>
> I mean, it's 11 characters vs. 4 (7 characters saved), but the whole
> typename is still 26. So the gain is questionable, and the use case
> where I'd be inclined to spell out the type like that is hard to imagine.
>
I believe you may be missing the most important point of the proposal.
My understanding is that:
auto<int> c = f();
Where f() could be:
vector<int> f() {}
Or
set<int> f() {}
But not
vector<float> f() {}
Please note that f() may not (actually should not) be overloads of the same
function.
> On the other hand, this might be problematic to implement because a
> template id is expected before '<', which auto is not. You would need to
> change the grammar for this to work.
>
I agree with you on this. It may get tricky.
Still... may be an idea worth considering.
> --
> 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/3796e4db-2227-8d38-2e36-f3dace1deffc%40gmail.com
> .
>
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CA%2BfGSbPi9goTyEz%2BExPWfR4L5J5_ZW4iNbo1SqK15GMO8A-2ew%40mail.gmail.com.
--001a1140b9ac8a4d4e0557dbad39
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div><br><div class=3D"gmail_quote"><div dir=3D"auto">On Mon, Aug 28, 2017 =
at 6:41 PM Andrey Semashev <<a href=3D"mailto:andrey.semashev@gmail.com"=
>andrey.semashev@gmail.com</a>> wrote:<br></div><blockquote class=3D"gma=
il_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-lef=
t:1ex">On 08/28/17 23:31, <a href=3D"mailto:i59developer@gmail.com" target=
=3D"_blank">i59developer@gmail.com</a> wrote:<br>
> Basic example of the proposed feature:<br>
> |<br>
> std::vector<int>&get_numbers();<br>
><br>
> auto<int>&numbers =3Dget_numbers();<br>
> |<br>
><br>
> The idea behind this is to allow explicitly defining what template<br>
> arguments you are expecting from the right-hand side, without requirin=
g<br>
> a specific implementation. This would give the benefits of auto in<br>
> providing the means for replacing say a container, without losing the<=
br>
> ability to see what we are operating on (in this case an integer).<br>
<br>
IMHO, this feature doesn't look compelling enough. I think one of the<b=
r>
main selling points of auto was not having to type the long typenames,<br>
especially of iterators, especially in templated code. So instead of<br>
<br>
=C2=A0 =C2=A0typename std::vector<T>::iterator it =3D c.begin();<br>
<br>
you could write<br>
<br>
=C2=A0 =C2=A0auto it =3D c.begin();<br>
<br>
With your proposal, you don't really save much:<br>
<br>
=C2=A0 =C2=A0typename auto<T>::iterator it =3D c.begin();<br>
<br>
I mean, it's 11 characters vs. 4 (7 characters saved), but the whole<br=
>
typename is still 26. So the gain is questionable, and the use case<br>
where I'd be inclined to spell out the type like that is hard to imagin=
e.<br>
</blockquote><div dir=3D"auto"><br></div><div dir=3D"auto">I believe you ma=
y be missing the most important point of the proposal.</div><div dir=3D"aut=
o"><br></div><div dir=3D"auto">My understanding is that:</div><div dir=3D"a=
uto"><br></div><div dir=3D"auto">auto<int> c =3D f();</div><div dir=
=3D"auto"><br></div><div dir=3D"auto">Where f() could be:</div><div dir=3D"=
auto"><br></div><div dir=3D"auto">vector<int> f() {}</div><div dir=3D=
"auto"><br></div><div dir=3D"auto">Or</div><div dir=3D"auto"><br></div><div=
dir=3D"auto">set<int> f() {}</div><div dir=3D"auto"><br></div><div d=
ir=3D"auto">But not</div><div dir=3D"auto"><br></div><div dir=3D"auto">vect=
or<float> f() {}</div><div dir=3D"auto"><br></div><div dir=3D"auto">P=
lease note that f() may not (actually should not) be overloads of the same =
function.</div><div dir=3D"auto"><br></div><blockquote class=3D"gmail_quote=
" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><=
br>
On the other hand, this might be problematic to implement because a<br>
template id is expected before '<', which auto is not. You would=
need to<br>
change the grammar for this to work.<br>
</blockquote><div dir=3D"auto"><br></div><div dir=3D"auto">I agree with you=
on this. It may get tricky.</div><div dir=3D"auto">Still... may be an idea=
worth considering.</div><div dir=3D"auto"><br></div><blockquote class=3D"g=
mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l=
eft:1ex"><br>
--<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%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/3796e4db-2227-8d38-2e36-f3dace1deffc%=
40gmail.com" rel=3D"noreferrer" target=3D"_blank">https://groups.google.com=
/a/isocpp.org/d/msgid/std-proposals/3796e4db-2227-8d38-2e36-f3dace1deffc%40=
gmail.com</a>.<br>
</blockquote></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CA%2BfGSbPi9goTyEz%2BExPWfR4L5J5_ZW4i=
Nbo1SqK15GMO8A-2ew%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CA%2BfGSbPi9g=
oTyEz%2BExPWfR4L5J5_ZW4iNbo1SqK15GMO8A-2ew%40mail.gmail.com</a>.<br />
--001a1140b9ac8a4d4e0557dbad39--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Mon, 28 Aug 2017 20:58:23 -0700 (PDT)
Raw View
------=_Part_7588_1385566581.1503979103484
Content-Type: multipart/alternative;
boundary="----=_Part_7589_1324361865.1503979103484"
------=_Part_7589_1324361865.1503979103484
Content-Type: text/plain; charset="UTF-8"
Wouldn't it make more sense to just let Concepts + Ranges handle this?
Container<int> = ...;
After all, `auto<int>` would match any type that takes a single template
parameter of type `int`. But that's not what you want; you want to take
only containers of `int`s.
--
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/e94ca6f9-5f44-4289-a655-0ac459d9ec64%40isocpp.org.
------=_Part_7589_1324361865.1503979103484
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Wouldn't it make more sense to just let Concepts + Ran=
ges handle this?<br><br><div style=3D"background-color: rgb(250, 250, 250);=
border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; =
overflow-wrap: break-word;" class=3D"prettyprint"><code class=3D"prettyprin=
t"><div class=3D"subprettyprint"><span style=3D"color: #606;" class=3D"styl=
ed-by-prettify">Container</span><span style=3D"color: #080;" class=3D"style=
d-by-prettify"><int></span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">...;</spa=
n></div></code></div><br>After all, `auto<int>` would match any type =
that takes a single template parameter of type `int`. But that's not wh=
at you want; you want to take only containers of `int`s.<br></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/e94ca6f9-5f44-4289-a655-0ac459d9ec64%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/e94ca6f9-5f44-4289-a655-0ac459d9ec64=
%40isocpp.org</a>.<br />
------=_Part_7589_1324361865.1503979103484--
------=_Part_7588_1385566581.1503979103484--
.
Author: Andrey Semashev <andrey.semashev@gmail.com>
Date: Tue, 29 Aug 2017 11:29:12 +0300
Raw View
On 08/29/17 06:58, Nicol Bolas wrote:
> Wouldn't it make more sense to just let Concepts + Ranges handle this?
>
> |
> Container<int>=...;
> |
>
> After all, `auto<int>` would match any type that takes a single template
> parameter of type `int`. But that's not what you want; you want to take
> only containers of `int`s.
Yes, this would be more interesting.
--
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/b41fccb0-8dbd-a1a2-0af5-50d45d13eac6%40gmail.com.
.
Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Tue, 29 Aug 2017 22:46:06 -0700 (PDT)
Raw View
------=_Part_1287_402492171.1504071966204
Content-Type: multipart/alternative;
boundary="----=_Part_1288_120928440.1504071966205"
------=_Part_1288_120928440.1504071966205
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Monday, August 28, 2017 at 8:58:23 PM UTC-7, Nicol Bolas wrote:
>
> Wouldn't it make more sense to just let Concepts + Ranges handle this?
>
> Container<int> =3D ...;
>
> After all, `auto<int>` would match any type that takes a single template=
=20
> parameter of type `int`. But that's not what you want; you want to take=
=20
> only containers of `int`s.
>
+1. Except that, as I understand it, the following is not allowed in=20
Concepts =E2=80=94
Container<int> x =3D get_vector(); // OK
Container<Numeric> y =3D get_vector(); // error AFAIK, the name of the=
=20
type modeling Numeric can't be deduced
Giving the programmer such a "half-baked" deduction syntax might just=20
provoke more confusion and frustration than providing no syntax at all.
https://wandbox.org/permlink/2URFktbet3JlylJ2
Container_int x =3D get_vecint(); // ok
Container<int> y =3D get_vecint(); // ok
std::vector<Integral> z =3D get_vecint(); // ok
Container<Integral> w =3D get_vecint(); // ERROR
The other problem I see with i59's original idea is that
auto<int>& numbers =3D get_numbers();
seems to be treating "auto" as the name of a class template... or maybe an=
=20
alias template?
Would people expect either or both of the following attempts to work, or to=
=20
fail?
template<class T, class A =3D std::allocator<T>> class Vec { };
template<class A, class T> class Cev2 { };
template<class T> using Cev =3D Cev2<std::allocator<T>, T>;
* auto<int> a =3D Vec<int>();*
* auto<int> b =3D Cev<int>();*
If you thought "b" should work, then what about "c"=E2=80=94
* auto<int> c =3D Cev2<std::allocator<int>, int>();*
Would your answer for "a" change if the default value for template=20
parameter "A" were not visible in this translation unit?
Modifying the C++ type-system is *hard*, and it just keeps getting harder.=
=20
Alias templates were kind of a miracle; you oughtn't expect to pull off=20
such a miracle without a lot of preparation. :)
=E2=80=93Arthur
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/5f48d628-d85c-40ef-9858-41c353806ac8%40isocpp.or=
g.
------=_Part_1288_120928440.1504071966205
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Monday, August 28, 2017 at 8:58:23 PM UTC-7, Nicol Bola=
s 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">Would=
n't it make more sense to just let Concepts + Ranges handle this?<br><b=
r><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,=
187);border-style:solid;border-width:1px"><code><div><span style=3D"color:#=
606">Container</span><span style=3D"color:#080"><int></span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#660">=3D</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">...;</span></div></code>=
</div><br>After all, `auto<int>` would match any type that takes a si=
ngle template parameter of type `int`. But that's not what you want; yo=
u want to take only containers of `int`s.<br></div></blockquote><div><br></=
div><div>+1. Except that, as I understand it, the following is not allowed =
in Concepts =E2=80=94</div><div><br></div><div>=C2=A0 =C2=A0 Container<i=
nt> x =3D get_vector(); =C2=A0 // OK</div><div>=C2=A0 =C2=A0 Container&l=
t;Numeric> y =3D get_vector(); =C2=A0// error AFAIK, the name of the typ=
e modeling Numeric can't be deduced</div><div><br></div><div>Giving the=
programmer such a "half-baked" deduction syntax might just provo=
ke more confusion and frustration than providing no syntax at all.</div><di=
v><a href=3D"https://wandbox.org/permlink/2URFktbet3JlylJ2">https://wandbox=
..org/permlink/2URFktbet3JlylJ2</a><br></div><div><br></div><div><div>=C2=A0=
=C2=A0 Container_int x =3D get_vecint(); =C2=A0// ok</div><div>=C2=A0 =C2=
=A0 Container<int> y =3D get_vecint(); =C2=A0// ok</div><div>=C2=A0 =
=C2=A0 std::vector<Integral> z =3D get_vecint(); =C2=A0// ok</div><di=
v>=C2=A0 =C2=A0 Container<Integral> w =3D get_vecint(); =C2=A0// ERRO=
R</div></div><div><br></div><div>The other problem I see with i59's ori=
ginal idea is that</div><div><br></div><div>=C2=A0 =C2=A0=C2=A0<span style=
=3D"font-family: monospace; color: rgb(0, 0, 136);">auto</span><span style=
=3D"font-family: monospace; color: rgb(0, 136, 0);"><</span><font color=
=3D"#000000" style=3D"font-family: monospace;"><span style=3D"color: rgb(0,=
136, 0);">int</span></font><span style=3D"font-family: monospace; color: r=
gb(0, 136, 0);">></span><span style=3D"font-family: monospace; color: rg=
b(102, 102, 0);">&</span><span style=3D"font-family: monospace; color: =
rgb(0, 0, 0);">=C2=A0numbers=C2=A0</span><span style=3D"font-family: monosp=
ace; color: rgb(102, 102, 0);">=3D</span><span style=3D"font-family: monosp=
ace; background-color: rgb(250, 250, 250);"><span style=3D"color: rgb(0, 0,=
0);">=C2=A0</span></span><span style=3D"font-family: monospace; color: rgb=
(0, 0, 0);">get_numbers</span><font face=3D"Arial, Helvetica, sans-serif"><=
span style=3D"color: rgb(102, 102, 0);">()</span></font><font color=3D"#000=
000" style=3D"font-family: monospace; background-color: rgb(250, 250, 250);=
"><span style=3D"color: rgb(102, 102, 0);">;</span></font></div><div><br></=
div><div>seems to be treating "auto" as the name of a class templ=
ate... or maybe an alias template?</div><div>Would people expect either or =
both of the following attempts to work, or to fail?</div><div><br></div><di=
v>=C2=A0 =C2=A0 template<class T, class A =3D std::allocator<T>>=
; class Vec { };</div><div><br></div><div><div>=C2=A0 =C2=A0 template<cl=
ass A, class T> class Cev2 { };</div></div><div>=C2=A0 =C2=A0 template&l=
t;class T> using Cev =3D Cev2<std::allocator<T>, T>;</div><d=
iv><br></div><div><b>=C2=A0 =C2=A0 auto<int> a =3D Vec<int>();<=
/b></div><div><b>=C2=A0 =C2=A0 auto<int> b =3D Cev<int>();</b><=
/div><div><br></div><div>If you thought "b" should work, then wha=
t about "c"=E2=80=94</div><div><br></div><div><b>=C2=A0 =C2=A0 au=
to<int> c =3D Cev2<std::allocator<int>, int>();</b></div>=
<div><br></div><div>Would your answer for "a" change if the defau=
lt value for template parameter "A" were not visible in this tran=
slation unit?</div><div><br></div><div>Modifying the C++ type-system is=C2=
=A0<i>hard</i>, and it just keeps getting harder. Alias templates were kind=
of a miracle; you oughtn't expect to pull off such a miracle without a=
lot of preparation. :)</div><div><br></div><div>=E2=80=93Arthur</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/5f48d628-d85c-40ef-9858-41c353806ac8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5f48d628-d85c-40ef-9858-41c353806ac8=
%40isocpp.org</a>.<br />
------=_Part_1288_120928440.1504071966205--
------=_Part_1287_402492171.1504071966204--
.