Topic: [c++std-core-27216] An implementation of
Author: Bjarne Stroustrup <bjarne@stroustrup.com>
Date: Thu, 05 Mar 2015 22:05:39 -0500
Raw View
(1) people always ask for heavier syntax from new features
(2) people learn
(3) people always complain that the syntax they insisted on is too heavy
handed
I remember serious and well-meaning criticism that allowing "sqrt(2)"
would lead to misuse and bugs and that it was *good* for people and
especially for maintenance if people had to write "sqrt(2.)" or
"sqrt((double)2)" to avoid crashes.
Yes, someone is going to write "void f(auto);" and be surprised. In
particular, someone is going to write "void ff(auto,auto);" and be
surprised that "ff("hello",2)" is allowed, but I think that ship has
sailed. What we really have to get into our/people's heads is that
"auto" is just the weakest constraint. Even a concept that requires
nothing is stronger because "void ff(Unconstrained, Unconstrained);"
will not accept "ff("hello",2)". There are examples that are better
expressed using the less terse notations. We will eventually settle on
conventions for use.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.
To post to this group, send email to std-discussion@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-discussion/.
.
Author: Tom Honermann <thonermann@coverity.com>
Date: Thu, 5 Mar 2015 23:44:56 -0500
Raw View
On 03/05/2015 10:05 PM, Bjarne Stroustrup wrote:
> (1) people always ask for heavier syntax from new features
> (2) people learn
> (3) people always complain that the syntax they insisted on is too heavy
> handed
I think there is truth in that. However, I think some other languages
have demonstrated the opposite problem. For example, Perl has been
criticized (fairly or not, I'm not judging) for allowing overly terse
syntax and sometimes termed a "write-only language" due to a common
perception that maintaining Perl code is difficult as a result. I'm not
trying to defend that argument here, just pointing out that the
perception exists.
I think the abbreviated syntax goes too far as currently proposed. It
is hard to imagine a more terse syntax that doesn't require dropping
type placeholders completely. I stated elsewhere in this thread that I
don't mind the current, rather heavy, template syntax, but that doesn't
mean that I wouldn't appreciate a lighter syntax. If there were not
significant semantic differences between template function definitions
and non-template function definitions, then I would love the abbreviated
syntax. The fact is though, that there are significant semantic
differences and some of them are quite subtle.
I don't feel concerned about point of usage of functions declared with
the abbreviated syntax. The behavioral differences aren't that great in
that case. My concern is with maintenance of functions declared with
this syntax and maintainers not realizing that a template is being
modified. Richard supplied an excellent list a few emails back
illustrating some of the problems one can encounter switching a simple
traditionally declared template function to an abbreviated one. I think
his insights should not be overlooked here (or, anywhere else, really).
I would be quite happy with the smallest addition to the proposal that
makes it clear that "this is a template function" and that doesn't rely
on my ability to scan for 'auto' or identify the name of a concept in
the parameter list.
We have this for lambdas:
auto l = [](auto x) { return x; }
If we could do (something like) these for generic functions, I would be
thrilled:
auto <>f(auto x) { return x; }
auto <>f(Iterator i) { return i; }
Tom.
--
---
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: Tony V E <tvaneerd@gmail.com>
Date: Fri, 6 Mar 2015 02:07:17 -0500
Raw View
--001a1132f242b561e80510995501
Content-Type: text/plain; charset=UTF-8
On Thu, Mar 5, 2015 at 11:44 PM, Tom Honermann <thonermann@coverity.com>
wrote:
> We have this for lambdas:
> auto l = [](auto x) { return x; }
> If we could do (something like) these for generic functions, I would be
> thrilled:
> auto <>f(auto x) { return x; }
> auto <>f(Iterator i) { return i; }
>
The terse syntax with just 'auto' doesn't bother me (I think I will learn
to scan for 'auto' params), but if we do choose to have distinctive syntax
to note that it is a template, then I'll make a crazy suggestion: use the
word 'template'
template void f(auto x) { ... }
Although 'auto' doesn't bother me, as others have mentioned, Concepts give
no hints:
void f(Number x) { ... }
So either you know your concepts, or you IDE does (and gives them a
different color or something) or maybe that is a reason to use 'template':
template void f(Number x) { ... }
(and thus use 'template' for the 'auto' case as well)
Tony
--
---
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/.
--001a1132f242b561e80510995501
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 Thu, Mar 5, 2015 at 11:44 PM, Tom Honermann <span dir=3D"ltr"><<a=
href=3D"mailto:thonermann@coverity.com" target=3D"_blank">thonermann@cover=
ity.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We have thi=
s for lambdas:<br>
=C2=A0 auto l =3D [](auto x) { return x; }<br>
If we could do (something like) these for generic functions, I would be thr=
illed:<br>
=C2=A0 auto <>f(auto x) { return x; }<br>
=C2=A0 auto <>f(Iterator i) { return i; }<span class=3D"HOEnZb"><font=
color=3D"#888888"><br>
</font></span></blockquote><div><br></div><div>The terse syntax with just &=
#39;auto' doesn't bother me (I think I will learn to scan for '=
auto' params), but if we do choose to have distinctive syntax to note t=
hat it is a template, then I'll make a crazy suggestion: use the word &=
#39;template'<br><br></div><div>=C2=A0=C2=A0=C2=A0 template void f(auto=
x) { ... } <br></div></div><br></div><div class=3D"gmail_extra">Although &=
#39;auto' doesn't bother me, as others have mentioned, Concepts giv=
e no hints:<br><br></div><div class=3D"gmail_extra">=C2=A0=C2=A0=C2=A0 void=
f(Number x) { ... }<br><br></div><div class=3D"gmail_extra">So either you =
know your concepts, or you IDE does (and gives them a different color or so=
mething) or maybe that is a reason to use 'template':<br><br></div>=
<div class=3D"gmail_extra">=C2=A0=C2=A0=C2=A0 template void f(Number x) { .=
... }<br><br></div><div class=3D"gmail_extra">(and thus use 'template=
9; for the 'auto' case as well)<br><br></div><div class=3D"gmail_ex=
tra">Tony<br><br></div><div class=3D"gmail_extra"><br><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" 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 />
--001a1132f242b561e80510995501--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sat, 07 Mar 2015 17:26:28 +0100
Raw View
This is a multi-part message in MIME format.
--------------040008010001080806040309
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 06/03/15 08:07, Tony V E a =C3=A9crit :
>
>
> On Thu, Mar 5, 2015 at 11:44 PM, Tom Honermann=20
> <thonermann@coverity.com <mailto:thonermann@coverity.com>> wrote:
>
> We have this for lambdas:
> auto l =3D [](auto x) { return x; }
> If we could do (something like) these for generic functions, I
> would be thrilled:
> auto <>f(auto x) { return x; }
> auto <>f(Iterator i) { return i; }
>
>
> The terse syntax with just 'auto' doesn't bother me (I think I will=20
> learn to scan for 'auto' params), but if we do choose to have=20
> distinctive syntax to note that it is a template, then I'll make a=20
> crazy suggestion: use the word 'template'
>
> template void f(auto x) { ... }
>
> Although 'auto' doesn't bother me, as others have mentioned, Concepts=20
> give no hints:
>
> void f(Number x) { ... }
>
> So either you know your concepts, or you IDE does (and gives them a=20
> different color or something) or maybe that is a reason to use 'template'=
:
>
> template void f(Number x) { ... }
>
> (and thus use 'template' for the 'auto' case as well)
>
Could I suggest the use of something like '<>' to declare a type and the=20
required concept on the type parameter
void f(Number<>N x) { ... }
Number<>N x
stands for
a parameter x having type N satisfying Number.
The Concept or the type can be omitted
void f(<>N x) { ... }
a parameter x having type N without any constraint.
void f(Number<> x) { ... }
a parameter x having an unknown type satisfying the Number concept.
This
void f(<> x) { ... }
a parameter x having an unknown type without any constraint.
I we consider that auto mean no constraint, the more verbose syntax=20
could have a sens also
void f(auto<> x) { ... }
I we consider that auto mean any type, the more verbose syntax could=20
have a sens also
void f(<>auto x) { ... }
In any case we have the token <> that recall that we are defining a=20
template.
Vicente
--=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/.
--------------040008010001080806040309
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body text=3D"#000000" bgcolor=3D"#FFFFFF">
<div class=3D"moz-cite-prefix">Le 06/03/15 08:07, Tony V E a =C3=A9crit=
=C2=A0:<br>
</div>
<blockquote
cite=3D"mid:CAOHCbitiPm7SKQwXSBWrV2KOhNsAPcmGW7JZ1B13VO57Fip2ig@mail.gmail.=
com"
type=3D"cite">
<div dir=3D"ltr"><br>
<div class=3D"gmail_extra"><br>
<div class=3D"gmail_quote">On Thu, Mar 5, 2015 at 11:44 PM, Tom
Honermann <span dir=3D"ltr"><<a moz-do-not-send=3D"true"
href=3D"mailto:thonermann@coverity.com" target=3D"_blank">t=
honermann@coverity.com</a>></span>
wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">We have
this for lambdas:<br>
=C2=A0 auto l =3D [](auto x) { return x; }<br>
If we could do (something like) these for generic
functions, I would be thrilled:<br>
=C2=A0 auto <>f(auto x) { return x; }<br>
=C2=A0 auto <>f(Iterator i) { return i; }<span
class=3D"HOEnZb"><font color=3D"#888888"><br>
</font></span></blockquote>
<div><br>
</div>
<div>The terse syntax with just 'auto' doesn't bother me (I
think I will learn to scan for 'auto' params), but if we
do choose to have distinctive syntax to note that it is a
template, then I'll make a crazy suggestion: use the word
'template'<br>
<br>
</div>
<div>=C2=A0=C2=A0=C2=A0 template void f(auto x) { ... } <br>
</div>
</div>
<br>
</div>
<div class=3D"gmail_extra">Although 'auto' doesn't bother me, as
others have mentioned, Concepts give no hints:<br>
<br>
</div>
<div class=3D"gmail_extra">=C2=A0=C2=A0=C2=A0 void f(Number x) { ..=
.. }<br>
<br>
</div>
<div class=3D"gmail_extra">So either you know your concepts, or
you IDE does (and gives them a different color or something)
or maybe that is a reason to use 'template':<br>
<br>
</div>
<div class=3D"gmail_extra">=C2=A0=C2=A0=C2=A0 template void f(Numbe=
r x) { ... }<br>
<br>
</div>
<div class=3D"gmail_extra">(and thus use 'template' for the 'auto'
case as well)<br>
</div>
</div>
<br>
</blockquote>
Could I suggest the use of something like '<>' to declare a
type and the required concept on the type parameter<br>
<br>
=C2=A0=C2=A0=C2=A0 void f(Number<>N x) { ... }<br>
<br>
Number<>N x <br>
<br>
stands for<br>
<br>
a parameter x having type N satisfying Number.<br>
<br>
The Concept or the type can be omitted<br>
<br>
=C2=A0=C2=A0=C2=A0 void f(<>N x) { ... }<br>
<br>
a parameter x having type N without any constraint.<br>
<br>
=C2=A0=C2=A0=C2=A0 void f(Number<> x) { ... }<br>
<br>
a parameter x having an unknown type satisfying the Number concept.<br>
<br>
This <br>
<br>
=C2=A0=C2=A0=C2=A0 void f(<> x) { ... }<br>
<br>
a parameter x having an unknown type without any constraint.<br>
<br>
I we consider that auto mean no constraint, the more verbose syntax
could have a sens also<br>
<br>
=C2=A0=C2=A0=C2=A0 void f(auto<> x) { ... }<br>
<br>
I we consider that auto mean any type, the more verbose syntax could
have a sens also<br>
<br>
=C2=A0=C2=A0=C2=A0 void f(<>auto x) { ... }<br>
<br>
In any case we have the token <> that recall that we are
defining a template.<br>
<br>
Vicente<br>
<br>
<br>
<br>
<br>
<br>
</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" 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 />
--------------040008010001080806040309--
.