Topic: [c++std-core-27229] An implementation of
Author: John Spicer <jhs@edg.com>
Date: Fri, 6 Mar 2015 13:37:32 -0500
Raw View
--Apple-Mail=_77A51922-F6D1-4F50-AD7A-559CC8410C32
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
On Mar 6, 2015, at 1:27 PM, Herb Sutter <hsutter@microsoft.com> wrote:
> > To the novice C++ programmer, it isn't "all just programming." Whether =
something is a template matters.
> =20
> Why? Only because of where you put the definition, and that=E2=80=99s (a)=
teachable and (b) not new because the same issue exists already with:
> =20
> auto f() { =E2=80=A6 };
> =20
> This is not a template, but must appear in a header. This is amazingly si=
milar =E2=80=93 and easy to teach as =E2=80=9Cif the declaration mentions =
=E2=80=98auto=E2=80=99 or a concept name, the compiler needs the definition=
, either to deduce something or to inline the body into the caller.=E2=80=
=9D Right?
Actually, that is not right -- in fact, it is mostly wrong.
Only if the return type is deduced do you need a definition.
So:
void f(auto,auto);
void g(ForwardIterator);
do not need definitions.
John.
> =20
> Herb
> =20
> PS =E2=80=93 Since you mention =E2=80=9Cnovices=E2=80=9D writing template=
s, in my experience (and to my surprise) I=E2=80=99ve found that not only n=
ovices but also intermediate developers (like 5-7 year veterans) don=E2=80=
=99t write templates very much. [I expect this to change with concepts, for=
the good.] I discovered this by chance when I had a class exercise that in=
cluded writing a very simple template, and as I walked through the class du=
ring the exercise I was surprised that most of the groups asked about the s=
yntax for writing a template =E2=80=93 a dead giveaway that they didn=E2=80=
=99t write templates very often, yet these were pretty experienced develope=
rs who used C++ every day, but just never needed to write templates much in=
their normal code. To validate that this wasn=E2=80=99t just an outlier gr=
oup, I=E2=80=99ve watched that exercise in a number of classes over several=
years and found a similar result =E2=80=93 the majority of even reasonably=
experienced C++ programmers asked about the syntax for how to write a temp=
late.
> =20
> =20
> =20
> From: Nicol Bolas [mailto:jmckesson@gmail.com]=20
> Sent: Friday, March 6, 2015 9:21 AM
> To: std-discussion@isocpp.org
> Cc: c++std-core@accu.org; std-proposals@isocpp.org; faisalv@gmail.com; He=
rb Sutter
> Subject: Re: [c++std-core-27204] Re: An implementation of enhanced auto d=
eduction and abbreviated template syntax using Clang
> =20
> On Thursday, March 5, 2015 at 7:24:32 PM UTC-5, Herb Sutter wrote:
> To paraphrase Stroustrup, it=E2=80=99s not about functional programming a=
nd object-oriented programming and generic programming=E2=80=A6 =E2=80=9Cit=
=E2=80=99s all just programming.=E2=80=9D
> =20
> > Templates are a fundamentally different kind of construct
> =20
> Why? Every full specialization of a function template is just a function.
>=20
> OK, let's explore this.
>=20
> Let's say that I'm a novice C++ programmer. I don't really know much abou=
t the language. But I have some basic knowledge.
>=20
> Now, I've been told that when I write functions, I put a prototype in a h=
eader file so that other people can use it. But I also put the implementati=
on in a source file, so that it stays hidden. So I write:
>=20
> //header
> RetType func_name(Type1 arg1, ...);
>=20
> //source
> RetType func_name(Type1 arg1, ...)
> {
> //implementation
> }
>=20
>=20
> OK, fine.
>=20
> I've also been told about a different class of functions: template functi=
ons. For reasons I haven't been told and don't much care about (since I'm a=
novice), I have to put the implementation in the header file. So I know th=
at if I type the word "template", then that function's implementation has t=
o go into a header. So I always do this:
>=20
> //header
> template<typename T>
> RetType func_name_template(T arg1, ...)
> {
> //implementation
> }
>=20
> //source doesn't exist.
>=20
> =20
> OK, fine. So... explain to me, the novice C++ programmer, why this doesn'=
t work:
>=20
> //header
> RetType func_name_concept(ConceptName arg1, ...);
>=20
> //source
> RetType func_name_concept(ConceptName arg1, ...)
> {
> //implementation
> }
>=20
> Explain to me, the novice C++ programmer, why this thing which doesn't lo=
ok like a template suddenly became a template. Explain to me why I have to =
implement it in a header, even though it looks exactly like every other non=
-template function declaration/definition.
>=20
> To the novice C++ programmer, it isn't "all just programming." Whether so=
mething is a template matters.
>=20
> Oh, you could say, "well just put everything in a header." That's... insa=
ne. Compile times for C++ projects of significant size are already huge eve=
n when you try to only put what you need in headers. Adding the burden of s=
hoving everything in a header is crazy.
>=20
> Now, if you can promise me that the same version of C++ that will include=
this terse syntax will also include modules, I will immediately stop carin=
g. Once that exists, then most of the differences between template and non-=
template functions will be erased. And therefore, so too can the syntactic =
differences.
>=20
> But so long as there is a difference in how you implement template and no=
n-template functions, I say that there should be an obvious difference in s=
yntax too.
>=20
> =20
> > My issue is with, well, any syntax that declares a template without hav=
ing to type either the word "template" or the use of "<>" brackets.
> =20
> That ship has sailed:
> =20
> auto plus =3D [](auto x, auto y) { return x+y; }
> =20
> which even already decays to an ordinary pointer to function, etc.
>=20
> That doesn't decay into a function pointer. It can't; the operator() is a=
template.
> =20
> =20
> Clarifying Q: Are we mainly arguing about whether to require the three ch=
aracters =3D, [, and ] ?
> Except that there is a difference between creating a lambda (which create=
s a functor) and creating a function (which can be overloaded).
>=20
> =20
> Not only has the ship sailed, but I for one like the direction it=E2=80=
=99s sailing. I see no reason why functions should be forced to spell =E2=
=80=9Ctemplate=E2=80=9D and =E2=80=9C<>=E2=80=9D. What value does it add? I=
t=E2=80=99s =E2=80=9Cjust programming.=E2=80=9D In fact, if we didn=E2=80=
=99t have backward compatibility issues with unnamed parameters and such, I=
=E2=80=99d personally probably be fine with just =E2=80=9Cauto plus(x,y){x+=
y}=E2=80=9D as an equivalent function definition. That still doesn=E2=80=99=
t lose any information.
> =20
> Gratuitous syntax is often unnecessary and usually harmful. Saying
> =20
> template<class T, class U>
> auto(T x, U y) -> decltype(x+y) { return x+y; }
> =20
> does not appear to me to contain any more information than
> =20
> auto plus(auto x, auto y) { return x+y; }
> =20
> does it?
> If you take out the late specified return type (I specifically said that =
static deduction was fine), then I don't see the problem with the first one=
..
>=20
> =20
> Requiring the verbose syntax is gratuitous, if the verbose syntax does no=
t add information, does not serve to disambiguate anything, and does not hi=
ghlight a dangerous operation or anything else I can see that deserves to h=
ave attention called to it.
> =20
> There=E2=80=99s a disturbing (to me and at least some others) trend in C+=
+ these days: People seem to be very prone to wanting =E2=80=9Cmore syntax=
=E2=80=9D lately. It=E2=80=99s rather Vasa-like, if only lexically. Let me =
channel certain influential committee members and say: =E2=80=98People thes=
e days are always asking for more syntax! There=E2=80=99s no proposal they=
=E2=80=99ve seen that they couldn=E2=80=99t make uglier with more syntax!=
=E2=80=99
> =20
> Important note: The point here is NOT terseness for terseness=E2=80=99 sa=
ke. I am not arguing that terser is somehow better, that terseness is virtu=
ous in itself. Too many people glorify languages because they=E2=80=99re te=
rser; fewer characters alone doesn=E2=80=99t make code clearer. Rather, my =
point is to avoid gratuitous verbosity. At the other end of the pendulum, t=
oo many people glorify verbose syntax because they think _that_ is somehow =
inherently clearer; usually it isn=E2=80=99t. So I am arguing that neither =
is verbosity virtuous in itself.
> =20
> Herb
> The virtue to me of the large syntax of templates is this:
>=20
> Templates have to be treated differently from non-templates. They have di=
fferent needs of where their implementations live. And because of those nee=
ds, templates make your code compile slower. Even ignoring the compile-time=
cost of template instantiation, your source has to go in the header. And i=
f that header is included in more than one place, then the source for that =
template must be recompiled for every place it is included.
>=20
> Therefore, the bulky template syntax pokes you in the eye every time you =
write something that's going to compile slower. It immediately lets you kno=
w that this function operates under fundamentally different rules than regu=
lar functions.
>=20
> Again, if you could guarantee that we get modules alongside this syntax, =
I'd be fine, since using templates will not hurt your compile times nearly =
as much.
> =20
--=20
---=20
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 e=
mail 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-discuss=
ion/.
--Apple-Mail=_77A51922-F6D1-4F50-AD7A-559CC8410C32
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=
=3Dwindows-1252"><base href=3D"x-msg://936/"></head><body style=3D"word-wra=
p: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-sp=
ace; "><br><div><div>On Mar 6, 2015, at 1:27 PM, Herb Sutter <<a href=3D=
"mailto:hsutter@microsoft.com">hsutter@microsoft.com</a>> wrote:</div><b=
r class=3D"Apple-interchange-newline"><blockquote type=3D"cite"><div lang=
=3D"EN-US" link=3D"#0563C1" vlink=3D"#954F72" style=3D"font-family: Helveti=
ca; font-size: medium; font-style: normal; font-variant: normal; font-weigh=
t: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-al=
ign: -webkit-auto; text-indent: 0px; text-transform: none; white-space: nor=
mal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-=
text-stroke-width: 0px; "><div class=3D"WordSection1" style=3D"page: WordSe=
ction1; "><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-fam=
ily: 'Times New Roman', serif; "><span style=3D"font-size: 11pt; font-famil=
y: Calibri, sans-serif; color: rgb(31, 73, 125); ">></span><span class=
=3D"Apple-converted-space"> </span>To the novice C++ programmer, it<sp=
an class=3D"Apple-converted-space"> </span><i>isn't</i><span class=3D"=
Apple-converted-space"> </span>"all just programming." Whether somethi=
ng is a template<span class=3D"Apple-converted-space"> </span><i>matte=
rs</i>.<span style=3D"font-size: 11pt; font-family: Calibri, sans-serif; co=
lor: rgb(31, 73, 125); "><o:p></o:p></span></div><div style=3D"margin: 0in =
0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><sp=
an style=3D"font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(3=
1, 73, 125); "> </span></div><div style=3D"margin: 0in 0in 0.0001pt; f=
ont-size: 12pt; font-family: 'Times New Roman', serif; "><span style=3D"fon=
t-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">=
Why? Only because of where you put the definition, and that=E2=80=99s (a) t=
eachable and (b) not new because the same issue exists already with:<o:p></=
o:p></span></div><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; f=
ont-family: 'Times New Roman', serif; "><span style=3D"font-size: 11pt; fon=
t-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span></di=
v><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Ti=
mes New Roman', serif; "><span style=3D"font-size: 11pt; font-family: Calib=
ri, sans-serif; color: rgb(31, 73, 125); "> &n=
bsp; auto f() { =E2=
=80=A6 };<o:p></o:p></span></div><div style=3D"margin: 0in 0in 0.0001pt; fo=
nt-size: 12pt; font-family: 'Times New Roman', serif; "><span style=3D"font=
-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">&=
nbsp;</span></div><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; =
font-family: 'Times New Roman', serif; "><span style=3D"font-size: 11pt; fo=
nt-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">This is not a te=
mplate, but must appear in a header. This is amazingly similar =E2=80=93 an=
d easy to teach as =E2=80=9Cif the declaration mentions =E2=80=98auto=E2=80=
=99 or a concept name, the compiler needs the definition, either to deduce =
something or to inline the body into the caller.=E2=80=9D Right?</span></di=
v></div></div></blockquote><div><br></div><div>Actually, that is not right =
-- in fact, it is mostly wrong.</div><div><br></div><div>Only if the return=
type is deduced do you need a definition.</div><div><br></div><div>So:</di=
v><div><br></div><div><span class=3D"Apple-tab-span" style=3D"white-space:p=
re"> </span>void f(auto,auto);</div><div><span class=3D"Apple-tab-span" sty=
le=3D"white-space:pre"> </span>void g(ForwardIterator);</div><div><br></div=
><div>do not need definitions.</div><div><br></div><div>John.</div><br><blo=
ckquote type=3D"cite"><div lang=3D"EN-US" link=3D"#0563C1" vlink=3D"#954F72=
" style=3D"font-family: Helvetica; font-size: medium; font-style: normal; f=
ont-variant: normal; font-weight: normal; letter-spacing: normal; line-heig=
ht: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-tr=
ansform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-t=
ext-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class=3D"Word=
Section1" style=3D"page: WordSection1; "><div style=3D"margin: 0in 0in 0.00=
01pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=
=3D"font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 1=
25); "><o:p></o:p></span></div><div style=3D"margin: 0in 0in 0.0001pt; font=
-size: 12pt; font-family: 'Times New Roman', serif; "><span style=3D"font-s=
ize: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">&nb=
sp;</span></div><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; fo=
nt-family: 'Times New Roman', serif; "><span style=3D"font-size: 11pt; font=
-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Herb<o:p></o:p></s=
pan></div><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-fam=
ily: 'Times New Roman', serif; "><span style=3D"font-size: 11pt; font-famil=
y: Calibri, sans-serif; color: rgb(31, 73, 125); "> </span></div><div =
style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New=
Roman', serif; "><span style=3D"font-size: 11pt; font-family: Calibri, san=
s-serif; color: rgb(31, 73, 125); ">PS =E2=80=93 Since you mention =E2=80=
=9Cnovices=E2=80=9D writing templates, in my experience (and to my surprise=
) I=E2=80=99ve found that not only novices but also intermediate developers=
(like 5-7 year veterans) don=E2=80=99t write templates very much. [I expec=
t this to change with concepts, for the good.] I discovered this by chance =
when I had a class exercise that included writing a very simple template, a=
nd as I walked through the class during the exercise I was surprised that m=
ost of the groups asked about the syntax for writing a template =E2=80=93 a=
dead giveaway that they didn=E2=80=99t write templates very often, yet the=
se were pretty experienced developers who used C++ every day, but just neve=
r needed to write templates much in their normal code. To validate that thi=
s wasn=E2=80=99t just an outlier group, I=E2=80=99ve watched that exercise =
in a number of classes over several years and found a similar result =E2=80=
=93 the majority of even reasonably experienced C++ programmers asked about=
the syntax for how to write a template.<o:p></o:p></span></div><div style=
=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roma=
n', serif; "><span style=3D"font-size: 11pt; font-family: Calibri, sans-ser=
if; color: rgb(31, 73, 125); "> </span></div><div style=3D"margin: 0in=
0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><s=
pan style=3D"font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(=
31, 73, 125); "> </span></div><div style=3D"margin: 0in 0in 0.0001pt; =
font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=3D"fo=
nt-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "=
> </span></div><div style=3D"border-style: none none none solid; borde=
r-left-width: 1.5pt; border-left-color: blue; padding: 0in 0in 0in 4pt; "><=
div><div style=3D"border-style: solid none none; border-top-width: 1pt; bor=
der-top-color: rgb(225, 225, 225); padding: 3pt 0in 0in; "><div style=3D"ma=
rgin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', se=
rif; "><b><span style=3D"font-size: 11pt; font-family: Calibri, sans-serif;=
">From:</span></b><span style=3D"font-size: 11pt; font-family: Calibri, sa=
ns-serif; "><span class=3D"Apple-converted-space"> </span>Nicol Bolas =
[mailto:jmckesson@<a href=3D"http://gmail.com" style=3D"color: rgb(149, 79,=
114); text-decoration: underline; ">gmail.com</a>]<span class=3D"Apple-con=
verted-space"> </span><br><b>Sent:</b><span class=3D"Apple-converted-s=
pace"> </span>Friday, March 6, 2015 9:21 AM<br><b>To:</b><span class=
=3D"Apple-converted-space"> </span><a href=3D"mailto:std-discussion@is=
ocpp.org" style=3D"color: rgb(149, 79, 114); text-decoration: underline; ">=
std-discussion@isocpp.org</a><br><b>Cc:</b><span class=3D"Apple-converted-s=
pace"> </span><a href=3D"mailto:c++std-core@accu.org" style=3D"color: =
rgb(149, 79, 114); text-decoration: underline; ">c++std-core@accu.org</a>;<=
span class=3D"Apple-converted-space"> </span><a href=3D"mailto:std-pro=
posals@isocpp.org" style=3D"color: rgb(149, 79, 114); text-decoration: unde=
rline; ">std-proposals@isocpp.org</a>;<span class=3D"Apple-converted-space"=
> </span><a href=3D"mailto:faisalv@gmail.com" style=3D"color: rgb(149,=
79, 114); text-decoration: underline; ">faisalv@gmail.com</a>; Herb Sutter=
<br><b>Subject:</b><span class=3D"Apple-converted-space"> </span>Re: [=
c++std-core-27204] Re: An implementation of enhanced auto deduction and abb=
reviated template syntax using Clang<o:p></o:p></span></div></div></div><di=
v style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times N=
ew Roman', serif; "><o:p> </o:p></div><div><div style=3D"margin: 0in 0=
in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">On T=
hursday, March 5, 2015 at 7:24:32 PM UTC-5, Herb Sutter wrote:<o:p></o:p></=
div><blockquote style=3D"border-style: none none none solid; border-left-wi=
dth: 1pt; border-left-color: rgb(204, 204, 204); padding: 0in 0in 0in 6pt; =
margin-left: 4.8pt; margin-right: 0in; "><div style=3D"margin: 0in 0in 0.00=
01pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=
=3D"font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 1=
25); ">To paraphrase Stroustrup, it=E2=80=99s not about functional programm=
ing and object-oriented programming and generic programming=E2=80=A6 =E2=80=
=9Cit=E2=80=99s all<span class=3D"Apple-converted-space"> </span><i>ju=
st programming</i>.=E2=80=9D</span><o:p></o:p></div><div style=3D"margin: 0=
in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; ">=
<span style=3D"font-size: 11pt; font-family: Calibri, sans-serif; color: rg=
b(31, 73, 125); "> </span><o:p></o:p></div><div style=3D"margin: 0in 0=
in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><spa=
n style=3D"font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31=
, 73, 125); ">><span class=3D"Apple-converted-space"> </span></span=
>Templates are a fundamentally different kind of construct<o:p></o:p></div>=
<div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Time=
s New Roman', serif; "><span style=3D"font-size: 11pt; font-family: Calibri=
, sans-serif; color: rgb(31, 73, 125); "> </span><o:p></o:p></div><div=
style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times Ne=
w Roman', serif; "><span style=3D"font-size: 11pt; font-family: Calibri, sa=
ns-serif; color: rgb(31, 73, 125); ">Why? Every full specialization of a fu=
nction template is just a function.</span><o:p></o:p></div></blockquote><di=
v><p class=3D"MsoNormal" style=3D"margin: 0in 0in 12pt; font-size: 12pt; fo=
nt-family: 'Times New Roman', serif; "><br>OK, let's explore this.<br><br>L=
et's say that I'm a novice C++ programmer. I don't really know much about t=
he language. But I have some basic knowledge.<br><br>Now, I've been told th=
at when I write functions, I put a prototype in a header file so that other=
people can use it. But I also put the implementation in a source file, so =
that it stays hidden. So I write:<o:p></o:p></p><div style=3D"border: 1pt s=
olid rgb(187, 187, 187); padding: 0in; word-wrap: break-word; "><div style=
=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roma=
n', serif; background-color: rgb(250, 250, 250); "><span class=3D"styled-by=
-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; colo=
r: rgb(136, 0, 0); ">//header</span></span><span style=3D"font-size: 10pt; =
font-family: 'Courier New'; "><br></span><span class=3D"styled-by-prettify"=
><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(102=
, 0, 102); ">RetType</span></span><span class=3D"styled-by-prettify"><span =
style=3D"font-size: 10pt; font-family: 'Courier New'; "><span class=3D"Appl=
e-converted-space"> </span>func_name</span></span><span class=3D"style=
d-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; =
color: rgb(102, 102, 0); ">(</span></span><span class=3D"styled-by-prettify=
"><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(10=
2, 0, 102); ">Type1</span></span><span class=3D"styled-by-prettify"><span s=
tyle=3D"font-size: 10pt; font-family: 'Courier New'; "><span class=3D"Apple=
-converted-space"> </span>arg1</span></span><span class=3D"styled-by-p=
rettify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; color:=
rgb(102, 102, 0); ">,</span></span><span class=3D"styled-by-prettify"><spa=
n style=3D"font-size: 10pt; font-family: 'Courier New'; "> </span></sp=
an><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-=
family: 'Courier New'; color: rgb(102, 102, 0); ">...);</span></span><span =
style=3D"font-size: 10pt; font-family: 'Courier New'; "><br><br></span><spa=
n class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family:=
'Courier New'; color: rgb(136, 0, 0); ">//source</span></span><span style=
=3D"font-size: 10pt; font-family: 'Courier New'; "><br></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Couri=
er New'; color: rgb(102, 0, 102); ">RetType</span></span><span class=3D"sty=
led-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier New'=
; "><span class=3D"Apple-converted-space"> </span>func_name</span></sp=
an><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-=
family: 'Courier New'; color: rgb(102, 102, 0); ">(</span></span><span clas=
s=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Cour=
ier New'; color: rgb(102, 0, 102); ">Type1</span></span><span class=3D"styl=
ed-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier New';=
"><span class=3D"Apple-converted-space"> </span>arg1</span></span><sp=
an class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family=
: 'Courier New'; color: rgb(102, 102, 0); ">,</span></span><span class=3D"s=
tyled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier Ne=
w'; "> </span></span><span class=3D"styled-by-prettify"><span style=3D=
"font-size: 10pt; font-family: 'Courier New'; color: rgb(102, 102, 0); ">..=
..)</span></span><span style=3D"font-size: 10pt; font-family: 'Courier New';=
"><br></span><span class=3D"styled-by-prettify"><span style=3D"font-size: =
10pt; font-family: 'Courier New'; color: rgb(102, 102, 0); ">{</span></span=
><span style=3D"font-size: 10pt; font-family: 'Courier New'; "><br></span><=
span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-fami=
ly: 'Courier New'; color: rgb(136, 0, 0); ">//implementation</span></span><=
span style=3D"font-size: 10pt; font-family: 'Courier New'; "><br></span><sp=
an class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family=
: 'Courier New'; color: rgb(102, 102, 0); ">}</span></span><span style=3D"f=
ont-size: 10pt; font-family: 'Courier New'; "><o:p></o:p></span></div></div=
><p class=3D"MsoNormal" style=3D"margin: 0in 0in 12pt; font-size: 12pt; fon=
t-family: 'Times New Roman', serif; "><br><br>OK, fine.<br><br>I've also be=
en told about a different class of functions: template functions. For reaso=
ns I haven't been told and don't much care about (since I'm a novice), I ha=
ve to put the implementation in the header file. So I know that if I type t=
he word "template", then that function's implementation has to go into a he=
ader. So I always do this:<o:p></o:p></p><div style=3D"border: 1pt solid rg=
b(187, 187, 187); padding: 0in; word-wrap: break-word; "><div style=3D"marg=
in: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', seri=
f; background-color: rgb(250, 250, 250); "><span class=3D"styled-by-prettif=
y"><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(1=
36, 0, 0); ">//header</span></span><span style=3D"font-size: 10pt; font-fam=
ily: 'Courier New'; "><br></span><span class=3D"styled-by-prettify"><span s=
tyle=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(0, 0, 136);=
">template</span></span><span class=3D"styled-by-prettify"><span style=3D"=
font-size: 10pt; font-family: 'Courier New'; color: rgb(102, 102, 0); "><=
;</span></span><span class=3D"styled-by-prettify"><span style=3D"font-size:=
10pt; font-family: 'Courier New'; color: rgb(0, 0, 136); ">typename</span>=
</span><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; f=
ont-family: 'Courier New'; "><span class=3D"Apple-converted-space"> </=
span>T</span></span><span class=3D"styled-by-prettify"><span style=3D"font-=
size: 10pt; font-family: 'Courier New'; color: rgb(102, 102, 0); ">></sp=
an></span><span style=3D"font-size: 10pt; font-family: 'Courier New'; "><br=
></span><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; =
font-family: 'Courier New'; color: rgb(102, 0, 102); ">RetType</span></span=
><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-fa=
mily: 'Courier New'; "><span class=3D"Apple-converted-space"> </span>f=
unc_name_template</span></span><span class=3D"styled-by-prettify"><span sty=
le=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(102, 102, 0);=
">(</span></span><span class=3D"styled-by-prettify"><span style=3D"font-si=
ze: 10pt; font-family: 'Courier New'; ">T arg1</span></span><span class=3D"=
styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier N=
ew'; color: rgb(102, 102, 0); ">,</span></span><span class=3D"styled-by-pre=
ttify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; "> =
</span></span><span class=3D"styled-by-prettify"><span style=3D"font-size: =
10pt; font-family: 'Courier New'; color: rgb(102, 102, 0); ">...)</span></s=
pan><span style=3D"font-size: 10pt; font-family: 'Courier New'; "><br></spa=
n><span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-f=
amily: 'Courier New'; color: rgb(102, 102, 0); ">{</span></span><span style=
=3D"font-size: 10pt; font-family: 'Courier New'; "><br></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Couri=
er New'; color: rgb(136, 0, 0); ">//implementation</span></span><span style=
=3D"font-size: 10pt; font-family: 'Courier New'; "><br></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Couri=
er New'; color: rgb(102, 102, 0); ">}</span></span><span style=3D"font-size=
: 10pt; font-family: 'Courier New'; "><br><br></span><span class=3D"styled-=
by-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; co=
lor: rgb(136, 0, 0); ">//source doesn't exist.</span></span><span style=3D"=
font-size: 10pt; font-family: 'Courier New'; "><o:p></o:p></span></div></di=
v><p class=3D"MsoNormal" style=3D"margin: 0in 0in 12pt; font-size: 12pt; fo=
nt-family: 'Times New Roman', serif; "><br> <br>OK, fine. So... explai=
n to me, the novice C++ programmer, why this doesn't work:<o:p></o:p></p><d=
iv style=3D"border: 1pt solid rgb(187, 187, 187); padding: 0in; word-wrap: =
break-word; "><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font=
-family: 'Times New Roman', serif; background-color: rgb(250, 250, 250); ">=
<span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-fam=
ily: 'Courier New'; color: rgb(136, 0, 0); ">//header</span></span><span st=
yle=3D"font-size: 10pt; font-family: 'Courier New'; "><br></span><span clas=
s=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Cour=
ier New'; color: rgb(102, 0, 102); ">RetType</span></span><span class=3D"st=
yled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Courier New=
'; "><span class=3D"Apple-converted-space"> </span>func_name_concept</=
span></span><span class=3D"styled-by-prettify"><span style=3D"font-size: 10=
pt; font-family: 'Courier New'; color: rgb(102, 102, 0); ">(</span></span><=
span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-fami=
ly: 'Courier New'; color: rgb(102, 0, 102); ">ConceptName</span></span><spa=
n class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family:=
'Courier New'; "><span class=3D"Apple-converted-space"> </span>arg1</=
span></span><span class=3D"styled-by-prettify"><span style=3D"font-size: 10=
pt; font-family: 'Courier New'; color: rgb(102, 102, 0); ">,</span></span><=
span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-fami=
ly: 'Courier New'; "> </span></span><span class=3D"styled-by-prettify"=
><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(102=
, 102, 0); ">...);</span></span><span style=3D"font-size: 10pt; font-family=
: 'Courier New'; "><br><br></span><span class=3D"styled-by-prettify"><span =
style=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(136, 0, 0)=
; ">//source</span></span><span style=3D"font-size: 10pt; font-family: 'Cou=
rier New'; "><br></span><span class=3D"styled-by-prettify"><span style=3D"f=
ont-size: 10pt; font-family: 'Courier New'; color: rgb(102, 0, 102); ">RetT=
ype</span></span><span class=3D"styled-by-prettify"><span style=3D"font-siz=
e: 10pt; font-family: 'Courier New'; "><span class=3D"Apple-converted-space=
"> </span>func_name_concept</span></span><span class=3D"styled-by-pret=
tify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: rg=
b(102, 102, 0); ">(</span></span><span class=3D"styled-by-prettify"><span s=
tyle=3D"font-size: 10pt; font-family: 'Courier New'; color: rgb(102, 0, 102=
); ">ConceptName</span></span><span class=3D"styled-by-prettify"><span styl=
e=3D"font-size: 10pt; font-family: 'Courier New'; "><span class=3D"Apple-co=
nverted-space"> </span>arg1</span></span><span class=3D"styled-by-pret=
tify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: rg=
b(102, 102, 0); ">,</span></span><span class=3D"styled-by-prettify"><span s=
tyle=3D"font-size: 10pt; font-family: 'Courier New'; "> </span></span>=
<span class=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-fam=
ily: 'Courier New'; color: rgb(102, 102, 0); ">...)</span></span><span styl=
e=3D"font-size: 10pt; font-family: 'Courier New'; "><br></span><span class=
=3D"styled-by-prettify"><span style=3D"font-size: 10pt; font-family: 'Couri=
er New'; color: rgb(102, 102, 0); ">{</span></span><span style=3D"font-size=
: 10pt; font-family: 'Courier New'; "><br></span><span class=3D"styled-by-p=
rettify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; color:=
rgb(136, 0, 0); ">//implementation</span></span><span style=3D"font-size: =
10pt; font-family: 'Courier New'; "><br></span><span class=3D"styled-by-pre=
ttify"><span style=3D"font-size: 10pt; font-family: 'Courier New'; color: r=
gb(102, 102, 0); ">}</span></span><span style=3D"font-size: 10pt; font-fami=
ly: 'Courier New'; "><o:p></o:p></span></div></div><p class=3D"MsoNormal" s=
tyle=3D"margin: 0in 0in 12pt; font-size: 12pt; font-family: 'Times New Roma=
n', serif; "><br>Explain to me, the novice C++ programmer, why this thing w=
hich doesn't look like a template suddenly<span class=3D"Apple-converted-sp=
ace"> </span><i>became</i><span class=3D"Apple-converted-space"> =
</span>a template. Explain to me why I have to implement it in a header, ev=
en though it looks exactly like every other non-template function declarati=
on/definition.<br><br>To the novice C++ programmer, it<span class=3D"Apple-=
converted-space"> </span><i>isn't</i><span class=3D"Apple-converted-sp=
ace"> </span>"all just programming." Whether something is a template<s=
pan class=3D"Apple-converted-space"> </span><i>matters</i>.<br><br>Oh,=
you could say, "well just put<span class=3D"Apple-converted-space"> <=
/span><i>everything</i><span class=3D"Apple-converted-space"> </span>i=
n a header." That's... insane. Compile times for C++ projects of significan=
t size are already huge even when you try to only put what you need in head=
ers. Adding the burden of shoving everything in a header is crazy.<br><br>N=
ow, if you can promise me that the same version of C++ that will include th=
is terse syntax will also include<span class=3D"Apple-converted-space">&nbs=
p;</span><i>modules</i>, I will immediately stop caring. Once that exists, =
then most of the differences between template and non-template functions wi=
ll be erased. And therefore, so too can the syntactic differences.<br><br>B=
ut so long as there is a difference in how you implement template and non-t=
emplate functions, I say that there should be an obvious difference in synt=
ax too.<o:p></o:p></p></div><blockquote style=3D"border-style: none none no=
ne solid; border-left-width: 1pt; border-left-color: rgb(204, 204, 204); pa=
dding: 0in 0in 0in 6pt; margin-left: 4.8pt; margin-right: 0in; "><div style=
=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roma=
n', serif; "><span style=3D"font-size: 11pt; font-family: Calibri, sans-ser=
if; color: rgb(31, 73, 125); "> </span><o:p></o:p></div><div style=3D"=
margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; "><span style=3D"font-size: 11pt; font-family: Calibri, sans-serif; =
color: rgb(31, 73, 125); ">><span class=3D"Apple-converted-space"> =
</span></span>My issue is with, well, any syntax that declares a template w=
ithout having to type either the word "template" or the use of "<>" b=
rackets.<o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001pt; font-size:=
12pt; font-family: 'Times New Roman', serif; "><span style=3D"font-size: 1=
1pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> </s=
pan><o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12p=
t; font-family: 'Times New Roman', serif; "><span style=3D"font-size: 11pt;=
font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">That ship has=
sailed:</span><o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001pt; fon=
t-size: 12pt; font-family: 'Times New Roman', serif; "><span style=3D"font-=
size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">&n=
bsp;</span><o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001pt; font-si=
ze: 12pt; font-family: 'Times New Roman', serif; "><span style=3D"font-size=
: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "> =
&nb=
sp; auto plus =3D [](auto x, auto y) { return x+y; }</span><o:p></o:p=
></div><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family=
: 'Times New Roman', serif; "><span style=3D"font-size: 11pt; font-family: =
Calibri, sans-serif; color: rgb(31, 73, 125); "> </span><o:p></o:p></d=
iv><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'T=
imes New Roman', serif; "><span style=3D"font-size: 11pt; font-family: Cali=
bri, sans-serif; color: rgb(31, 73, 125); ">which even already decays to an=
ordinary pointer to function, etc.</span><o:p></o:p></div></blockquote><di=
v><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Ti=
mes New Roman', serif; "><br>That doesn't decay into a function pointer. It=
can't; the operator() is a template.<br> <o:p></o:p></div></div><bloc=
kquote style=3D"border-style: none none none solid; border-left-width: 1pt;=
border-left-color: rgb(204, 204, 204); padding: 0in 0in 0in 6pt; margin-le=
ft: 4.8pt; margin-right: 0in; "><div style=3D"margin: 0in 0in 0.0001pt; fon=
t-size: 12pt; font-family: 'Times New Roman', serif; "><span style=3D"font-=
size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">&n=
bsp;</span><o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001pt; font-si=
ze: 12pt; font-family: 'Times New Roman', serif; "><span style=3D"font-size=
: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">Clarif=
ying Q: Are we mainly arguing about whether to require the three characters=
=3D, [, and ] ?</span><o:p></o:p></div></blockquote><div><p class=3D"MsoNo=
rmal" style=3D"margin: 0in 0in 12pt; font-size: 12pt; font-family: 'Times N=
ew Roman', serif; ">Except that there is a difference between creating a la=
mbda (which creates a functor) and creating a function (which can be overlo=
aded).<o:p></o:p></p></div><blockquote style=3D"border-style: none none non=
e solid; border-left-width: 1pt; border-left-color: rgb(204, 204, 204); pad=
ding: 0in 0in 0in 6pt; margin-left: 4.8pt; margin-right: 0in; "><div style=
=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roma=
n', serif; "><span style=3D"font-size: 11pt; font-family: Calibri, sans-ser=
if; color: rgb(31, 73, 125); "> </span><o:p></o:p></div><div style=3D"=
margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; "><span style=3D"font-size: 11pt; font-family: Calibri, sans-serif; =
color: rgb(31, 73, 125); ">Not only has the ship sailed, but I for one like=
the direction it=E2=80=99s sailing. I see no reason why functions should b=
e forced to spell =E2=80=9Ctemplate=E2=80=9D and =E2=80=9C<>=E2=80=9D=
.. What value does it add? It=E2=80=99s =E2=80=9Cjust programming.=E2=80=9D =
In fact, if we didn=E2=80=99t have backward compatibility issues with unnam=
ed parameters and such, I=E2=80=99d personally probably be fine with just =
=E2=80=9Cauto plus(x,y){x+y}=E2=80=9D as an equivalent function definition.=
That still doesn=E2=80=99t lose any information.</span><o:p></o:p></div><d=
iv style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times =
New Roman', serif; "><span style=3D"font-size: 11pt; font-family: Calibri, =
sans-serif; color: rgb(31, 73, 125); "> </span><o:p></o:p></div><div s=
tyle=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New =
Roman', serif; "><span style=3D"font-size: 11pt; font-family: Calibri, sans=
-serif; color: rgb(31, 73, 125); ">Gratuitous syntax is often unnecessary a=
nd usually harmful. Saying</span><o:p></o:p></div><div style=3D"margin: 0in=
0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><s=
pan style=3D"font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(=
31, 73, 125); "> </span><o:p></o:p></div><div style=3D"margin: 0in 0in=
0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span =
style=3D"font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, =
73, 125); "> &nb=
sp; template<class T, class U></span><o:p></o=
:p></div><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-fami=
ly: 'Times New Roman', serif; "><span style=3D"font-size: 11pt; font-family=
: Calibri, sans-serif; color: rgb(31, 73, 125); "> &=
nbsp; auto(T x,=
U y) -> decltype(x+y) { return x+y; }</span><o:p></o:p></div><div style=
=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roma=
n', serif; "><span style=3D"font-size: 11pt; font-family: Calibri, sans-ser=
if; color: rgb(31, 73, 125); "> </span><o:p></o:p></div><div style=3D"=
margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', =
serif; "><span style=3D"font-size: 11pt; font-family: Calibri, sans-serif; =
color: rgb(31, 73, 125); ">does not appear to me to contain any more inform=
ation than</span><o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001pt; f=
ont-size: 12pt; font-family: 'Times New Roman', serif; "><span style=3D"fon=
t-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">=
</span><o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001pt; font-=
size: 12pt; font-family: 'Times New Roman', serif; "><span style=3D"font-si=
ze: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">&nbs=
p; &=
nbsp; auto plus(auto x, auto y) { return x+y; }</span><o:p></o:p></di=
v><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Ti=
mes New Roman', serif; "><span style=3D"font-size: 11pt; font-family: Calib=
ri, sans-serif; color: rgb(31, 73, 125); "> </span><o:p></o:p></div><d=
iv style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times =
New Roman', serif; "><span style=3D"font-size: 11pt; font-family: Calibri, =
sans-serif; color: rgb(31, 73, 125); ">does it?</span><o:p></o:p></div></bl=
ockquote><div><div style=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font=
-family: 'Times New Roman', serif; ">If you take out the late specified ret=
urn type (I specifically said that static deduction was fine), then I don't=
see the problem with the first one.<br><br> <o:p></o:p></div></div><b=
lockquote style=3D"border-style: none none none solid; border-left-width: 1=
pt; border-left-color: rgb(204, 204, 204); padding: 0in 0in 0in 6pt; margin=
-left: 4.8pt; margin-right: 0in; "><div style=3D"margin: 0in 0in 0.0001pt; =
font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=3D"fo=
nt-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "=
>Requiring the verbose syntax is gratuitous, if the verbose syntax does not=
add information, does not serve to disambiguate anything, and does not hig=
hlight a dangerous operation or anything else I can see that deserves to ha=
ve attention called to it.</span><o:p></o:p></div><div style=3D"margin: 0in=
0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><s=
pan style=3D"font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(=
31, 73, 125); "> </span><o:p></o:p></div><div style=3D"margin: 0in 0in=
0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span =
style=3D"font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, =
73, 125); ">There=E2=80=99s a disturbing (to me and at least some others) t=
rend in C++ these days: People seem to be very prone to wanting =E2=80=9Cmo=
re syntax=E2=80=9D lately. It=E2=80=99s rather Vasa-like, if only lexically=
.. Let me channel certain influential committee members and say: =E2=80=98Pe=
ople these days are always asking for more syntax! There=E2=80=99s no propo=
sal they=E2=80=99ve seen that they couldn=E2=80=99t make uglier with more s=
yntax!=E2=80=99</span><o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001=
pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=
=3D"font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 1=
25); "> </span><o:p></o:p></div><div style=3D"margin: 0in 0in 0.0001pt=
; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style=3D"=
font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);=
">Important note: The point here is NOT terseness for terseness=E2=80=99 s=
ake. I am not arguing that terser is somehow better, that terseness is virt=
uous in itself. Too many people glorify languages because they=E2=80=99re t=
erser; fewer characters alone doesn=E2=80=99t make code clearer. Rather, my=
point is to avoid gratuitous verbosity. At the other end of the pendulum, =
too many people glorify verbose syntax because they think _that_ is somehow=
inherently clearer; usually it isn=E2=80=99t. So I am arguing that neither=
is verbosity virtuous in itself.</span><o:p></o:p></div><div style=3D"marg=
in: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', seri=
f; "><span style=3D"font-size: 11pt; font-family: Calibri, sans-serif; colo=
r: rgb(31, 73, 125); "> </span><o:p></o:p></div><div style=3D"margin: =
0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "=
><span style=3D"font-size: 11pt; font-family: Calibri, sans-serif; color: r=
gb(31, 73, 125); ">Herb</span><o:p></o:p></div></blockquote><div><div style=
=3D"margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roma=
n', serif; ">The virtue to me of the large syntax of templates is this:<br>=
<br>Templates have to be treated differently from non-templates. They have =
different needs of where their implementations live. And because of those n=
eeds, templates make your code compile slower. Even ignoring the compile-ti=
me cost of template instantiation, your source has to go in the header. And=
if that header is included in more than one place, then the source for tha=
t template must be recompiled for every place it is included.<br><br>Theref=
ore, the bulky template syntax pokes you in the eye every time you write so=
mething that's going to compile slower. It immediately lets you know that t=
his function operates under fundamentally different rules than regular func=
tions.<br><br>Again, if you could guarantee that we get modules alongside t=
his syntax, I'd be fine, since using templates will not hurt your compile t=
imes nearly as much.<o:p></o:p></div></div><div style=3D"margin: 0in 0in 0.=
0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><o:p>&nbs=
p;</o:p></div></div></div></div></div></blockquote></div><br></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Discussion" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-discussion+unsubscribe@isocpp.org">std-discus=
sion+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-discussion@isocp=
p.org">std-discussion@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-discussion/">http://groups.google.com/a/isocpp.org/group/std-discussion=
/</a>.<br />
--Apple-Mail=_77A51922-F6D1-4F50-AD7A-559CC8410C32--
.
Author: "'Geoffrey Romer' via ISO C++ Standard - Discussion" <std-discussion@isocpp.org>
Date: Fri, 6 Mar 2015 11:27:21 -0800
Raw View
--001a1147b5766b7da70510a3acae
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Fri, Mar 6, 2015 at 10:27 AM, Herb Sutter <hsutter@microsoft.com> wrote:
> > To the novice C++ programmer, it *isn't* "all just programming."
> Whether something is a template *matters*.
>
>
>
> Why? Only because of where you put the definition, and that=E2=80=99s (a)
> teachable and (b) not new because the same issue exists already with:
>
>
>
> auto f() { =E2=80=A6 };
>
>
>
> This is not a template, but must appear in a header. This is amazingly
> similar =E2=80=93 and easy to teach as =E2=80=9Cif the declaration mentio=
ns =E2=80=98auto=E2=80=99 or a
> concept name, the compiler needs the definition, either to deduce somethi=
ng
> or to inline the body into the caller.=E2=80=9D Right?
>
>
>
> Herb
>
>
>
> PS =E2=80=93 Since you mention =E2=80=9Cnovices=E2=80=9D writing template=
s, in my experience (and
> to my surprise) I=E2=80=99ve found that not only novices but also interme=
diate
> developers (like 5-7 year veterans) don=E2=80=99t write templates very mu=
ch. [I
> expect this to change with concepts, for the good.] I discovered this by
> chance when I had a class exercise that included writing a very simple
> template, and as I walked through the class during the exercise I was
> surprised that most of the groups asked about the syntax for writing a
> template =E2=80=93 a dead giveaway that they didn=E2=80=99t write templat=
es very often, yet
> these were pretty experienced developers who used C++ every day, but just
> never needed to write templates much in their normal code. To validate th=
at
> this wasn=E2=80=99t just an outlier group, I=E2=80=99ve watched that exer=
cise in a number
> of classes over several years and found a similar result =E2=80=93 the ma=
jority of
> even reasonably experienced C++ programmers asked about the syntax for ho=
w
> to write a template.
>
This very much matches my experience- as far as I can tell, the vast
majority of C++ code is non-template code. But why is that surprising, and
why do you expect concepts to change it?
>
>
>
>
>
>
> *From:* Nicol Bolas [mailto:jmckesson@gmail.com]
> *Sent:* Friday, March 6, 2015 9:21 AM
> *To:* std-discussion@isocpp.org
> *Cc:* c++std-core@accu.org; std-proposals@isocpp.org; faisalv@gmail.com;
> Herb Sutter
> *Subject:* Re: [c++std-core-27204] Re: An implementation of enhanced auto
> deduction and abbreviated template syntax using Clang
>
>
>
> On Thursday, March 5, 2015 at 7:24:32 PM UTC-5, Herb Sutter wrote:
>
> To paraphrase Stroustrup, it=E2=80=99s not about functional programming =
and
> object-oriented programming and generic programming=E2=80=A6 =E2=80=9Cit=
=E2=80=99s all *just
> programming*.=E2=80=9D
>
>
>
> > Templates are a fundamentally different kind of construct
>
>
>
> Why? Every full specialization of a function template is just a function.
>
>
> OK, let's explore this.
>
> Let's say that I'm a novice C++ programmer. I don't really know much abou=
t
> the language. But I have some basic knowledge.
>
> Now, I've been told that when I write functions, I put a prototype in a
> header file so that other people can use it. But I also put the
> implementation in a source file, so that it stays hidden. So I write:
>
> //header
> RetType func_name(Type1 arg1, ...);
>
> //source
> RetType func_name(Type1 arg1, ...)
> {
> //implementation
> }
>
>
>
> OK, fine.
>
> I've also been told about a different class of functions: template
> functions. For reasons I haven't been told and don't much care about (sin=
ce
> I'm a novice), I have to put the implementation in the header file. So I
> know that if I type the word "template", then that function's
> implementation has to go into a header. So I always do this:
>
> //header
> template<typename T>
> RetType func_name_template(T arg1, ...)
> {
> //implementation
> }
>
> //source doesn't exist.
>
>
>
> OK, fine. So... explain to me, the novice C++ programmer, why this doesn'=
t
> work:
>
> //header
> RetType func_name_concept(ConceptName arg1, ...);
>
> //source
> RetType func_name_concept(ConceptName arg1, ...)
> {
> //implementation
> }
>
>
> Explain to me, the novice C++ programmer, why this thing which doesn't
> look like a template suddenly *became* a template. Explain to me why I
> have to implement it in a header, even though it looks exactly like every
> other non-template function declaration/definition.
>
> To the novice C++ programmer, it *isn't* "all just programming." Whether
> something is a template *matters*.
>
> Oh, you could say, "well just put *everything* in a header." That's...
> insane. Compile times for C++ projects of significant size are already hu=
ge
> even when you try to only put what you need in headers. Adding the burden
> of shoving everything in a header is crazy.
>
> Now, if you can promise me that the same version of C++ that will include
> this terse syntax will also include *modules*, I will immediately stop
> caring. Once that exists, then most of the differences between template a=
nd
> non-template functions will be erased. And therefore, so too can the
> syntactic differences.
>
> But so long as there is a difference in how you implement template and
> non-template functions, I say that there should be an obvious difference =
in
> syntax too.
>
>
>
> > My issue is with, well, any syntax that declares a template without
> having to type either the word "template" or the use of "<>" brackets.
>
>
>
> That ship has sailed:
>
>
>
> auto plus =3D [](auto x, auto y) { return x+y; }
>
>
>
> which even already decays to an ordinary pointer to function, etc.
>
>
> That doesn't decay into a function pointer. It can't; the operator() is a
> template.
>
>
>
>
> Clarifying Q: Are we mainly arguing about whether to require the three
> characters =3D, [, and ] ?
>
> Except that there is a difference between creating a lambda (which
> creates a functor) and creating a function (which can be overloaded).
>
>
>
> Not only has the ship sailed, but I for one like the direction it=E2=80=
=99s
> sailing. I see no reason why functions should be forced to spell =E2=80=
=9Ctemplate=E2=80=9D
> and =E2=80=9C<>=E2=80=9D. What value does it add? It=E2=80=99s =E2=80=9Cj=
ust programming.=E2=80=9D In fact, if we
> didn=E2=80=99t have backward compatibility issues with unnamed parameters=
and such,
> I=E2=80=99d personally probably be fine with just =E2=80=9Cauto plus(x,y)=
{x+y}=E2=80=9D as an
> equivalent function definition. That still doesn=E2=80=99t lose any infor=
mation.
>
>
>
> Gratuitous syntax is often unnecessary and usually harmful. Saying
>
>
>
> template<class T, class U>
>
> auto(T x, U y) -> decltype(x+y) { return x+y; }
>
>
>
> does not appear to me to contain any more information than
>
>
>
> auto plus(auto x, auto y) { return x+y; }
>
>
>
> does it?
>
> If you take out the late specified return type (I specifically said that
> static deduction was fine), then I don't see the problem with the first o=
ne.
>
>
>
> Requiring the verbose syntax is gratuitous, if the verbose syntax does
> not add information, does not serve to disambiguate anything, and does no=
t
> highlight a dangerous operation or anything else I can see that deserves =
to
> have attention called to it.
>
>
>
> There=E2=80=99s a disturbing (to me and at least some others) trend in C+=
+ these
> days: People seem to be very prone to wanting =E2=80=9Cmore syntax=E2=80=
=9D lately. It=E2=80=99s
> rather Vasa-like, if only lexically. Let me channel certain influential
> committee members and say: =E2=80=98People these days are always asking f=
or more
> syntax! There=E2=80=99s no proposal they=E2=80=99ve seen that they couldn=
=E2=80=99t make uglier
> with more syntax!=E2=80=99
>
>
>
> Important note: The point here is NOT terseness for terseness=E2=80=99 sa=
ke. I am
> not arguing that terser is somehow better, that terseness is virtuous in
> itself. Too many people glorify languages because they=E2=80=99re terser;=
fewer
> characters alone doesn=E2=80=99t make code clearer. Rather, my point is t=
o avoid
> gratuitous verbosity. At the other end of the pendulum, too many people
> glorify verbose syntax because they think _that_ is somehow inherently
> clearer; usually it isn=E2=80=99t. So I am arguing that neither is verbos=
ity
> virtuous in itself.
>
>
>
> Herb
>
> The virtue to me of the large syntax of templates is this:
>
> Templates have to be treated differently from non-templates. They have
> different needs of where their implementations live. And because of those
> needs, templates make your code compile slower. Even ignoring the
> compile-time cost of template instantiation, your source has to go in the
> header. And if that header is included in more than one place, then the
> source for that template must be recompiled for every place it is include=
d.
>
> Therefore, the bulky template syntax pokes you in the eye every time you
> write something that's going to compile slower. It immediately lets you
> know that this function operates under fundamentally different rules than
> regular functions.
>
> Again, if you could guarantee that we get modules alongside this syntax,
> I'd be fine, since using templates will not hurt your compile times nearl=
y
> as much.
>
>
>
--=20
---=20
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 e=
mail 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-discuss=
ion/.
--001a1147b5766b7da70510a3acae
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">=
On Fri, Mar 6, 2015 at 10:27 AM, Herb Sutter <span dir=3D"ltr"><<a href=
=3D"mailto:hsutter@microsoft.com" target=3D"_blank">hsutter@microsoft.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">
<div lang=3D"EN-US" link=3D"#0563C1" vlink=3D"#954F72">
<div><span class=3D"">
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">></span> To the novice C++ program=
mer, it
<i>isn't</i> "all just programming." Whether something is a t=
emplate <i>matters</i>.<span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
</span><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&=
quot;Calibri",sans-serif;color:#1f497d">Why? Only because of where you=
put the definition, and that=E2=80=99s (a) teachable and (b) not new becau=
se the same issue exists already with:<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto f() { =E2=80=A6=
};<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">This is not a template, but must appe=
ar in a header. This is amazingly similar =E2=80=93 and easy to teach as =
=E2=80=9Cif the declaration mentions =E2=80=98auto=E2=80=99 or a concept na=
me, the
compiler needs the definition, either to deduce something or to inline the=
body into the caller.=E2=80=9D Right?<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">Herb<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">PS =E2=80=93 Since you mention =E2=80=
=9Cnovices=E2=80=9D writing templates, in my experience (and to my surprise=
) I=E2=80=99ve found that not only novices but also intermediate developers=
(like
5-7 year veterans) don=E2=80=99t write templates very much. [I expect this=
to change with concepts, for the good.] I discovered this by chance when I=
had a class exercise that included writing a very simple template, and as =
I walked through the class during the exercise
I was surprised that most of the groups asked about the syntax for writing=
a template =E2=80=93 a dead giveaway that they didn=E2=80=99t write templa=
tes very often, yet these were pretty experienced developers who used C++ e=
very day, but just never needed to write templates
much in their normal code. To validate that this wasn=E2=80=99t just an ou=
tlier group, I=E2=80=99ve watched that exercise in a number of classes over=
several years and found a similar result =E2=80=93 the majority of even re=
asonably experienced C++ programmers asked about the syntax
for how to write a template.</span></p></div></div></blockquote><div><br><=
/div><div>This very much matches my experience- as far as I can tell, the v=
ast majority of C++ code is non-template code. But why is that surprising, =
and why do you expect concepts to change it?</div><div>=C2=A0</div><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div lang=3D"EN-US" link=3D"#0563C1" vlink=3D"#954F7=
2"><div><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:=
"Calibri",sans-serif;color:#1f497d"><u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<div style=3D"border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in =
4.0pt">
<div>
<div style=3D"border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0in =
0in 0in">
<p class=3D"MsoNormal"><b><span style=3D"font-size:11.0pt;font-family:"=
;Calibri",sans-serif">From:</span></b><span style=3D"font-size:11.0pt;=
font-family:"Calibri",sans-serif"> Nicol Bolas [mailto:<a href=3D=
"mailto:jmckesson@gmail.com" target=3D"_blank">jmckesson@gmail.com</a>]
<br>
<b>Sent:</b> Friday, March 6, 2015 9:21 AM<br>
<b>To:</b> <a href=3D"mailto:std-discussion@isocpp.org" target=3D"_blank">s=
td-discussion@isocpp.org</a><br>
<b>Cc:</b> <a href=3D"mailto:c%2B%2Bstd-core@accu.org" target=3D"_blank">c+=
+std-core@accu.org</a>; <a href=3D"mailto:std-proposals@isocpp.org" target=
=3D"_blank">std-proposals@isocpp.org</a>; <a href=3D"mailto:faisalv@gmail.c=
om" target=3D"_blank">faisalv@gmail.com</a>; Herb Sutter<br>
<b>Subject:</b> Re: [c++std-core-27204] Re: An implementation of enhanced a=
uto deduction and abbreviated template syntax using Clang<u></u><u></u></sp=
an></p>
</div>
</div><div><div class=3D"h5">
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
<div>
<p class=3D"MsoNormal">On Thursday, March 5, 2015 at 7:24:32 PM UTC-5, Herb=
Sutter wrote:<u></u><u></u></p>
<blockquote style=3D"border:none;border-left:solid #cccccc 1.0pt;padding:0i=
n 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">To paraphrase Stroustrup, it=E2=80=99=
s not about functional programming and object-oriented programming and
generic programming=E2=80=A6 =E2=80=9Cit=E2=80=99s all <i>just programming=
</i>.=E2=80=9D</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">>
</span>Templates are a fundamentally different kind of construct<u></u><u><=
/u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">Why? Every full specialization of a f=
unction template is just a function.</span><u></u><u></u></p>
</div>
</div>
</blockquote>
<div>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt"><br>
OK, let's explore this.<br>
<br>
Let's say that I'm a novice C++ programmer. I don't really know=
much about the language. But I have some basic knowledge.<br>
<br>
Now, I've been told that when I write functions, I put a prototype in a=
header file so that other people can use it. But I also put the implementa=
tion in a source file, so that it stays hidden. So I write:<u></u><u></u></=
p>
<div style=3D"border:solid #bbbbbb 1.0pt;padding:0in 0in 0in 0in;word-wrap:=
break-word">
<div>
<p class=3D"MsoNormal" style=3D"background:#fafafa"><span><span style=3D"fo=
nt-size:10.0pt;font-family:"Courier New";color:#880000">//header<=
/span></span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#660066">RetType</span></span><span><span style=3D"font-size:10=
..0pt;font-family:"Courier New";color:black"> func_name</span></sp=
an><span><span style=3D"font-size:10.0pt;font-family:"Courier New"=
;;color:#666600">(</span></span><span><span style=3D"font-size:10.0pt;font-=
family:"Courier New";color:#660066">Type1</span></span><span><spa=
n style=3D"font-size:10.0pt;font-family:"Courier New";color:black=
">
arg1</span></span><span><span style=3D"font-size:10.0pt;font-family:"=
Courier New";color:#666600">,</span></span><span><span style=3D"font-s=
ize:10.0pt;font-family:"Courier New";color:black">
</span></span><span><span style=3D"font-size:10.0pt;font-family:"Couri=
er New";color:#666600">...);</span></span><span style=3D"font-size:10.=
0pt;font-family:"Courier New";color:black"><br>
<br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#880000">//source</span></span><span style=3D"font-size:10.0pt;=
font-family:"Courier New";color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#660066">RetType</span></span><span><span style=3D"font-size:10=
..0pt;font-family:"Courier New";color:black"> func_name</span></sp=
an><span><span style=3D"font-size:10.0pt;font-family:"Courier New"=
;;color:#666600">(</span></span><span><span style=3D"font-size:10.0pt;font-=
family:"Courier New";color:#660066">Type1</span></span><span><spa=
n style=3D"font-size:10.0pt;font-family:"Courier New";color:black=
">
arg1</span></span><span><span style=3D"font-size:10.0pt;font-family:"=
Courier New";color:#666600">,</span></span><span><span style=3D"font-s=
ize:10.0pt;font-family:"Courier New";color:black">
</span></span><span><span style=3D"font-size:10.0pt;font-family:"Couri=
er New";color:#666600">...)</span></span><span style=3D"font-size:10.0=
pt;font-family:"Courier New";color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#666600">{</span></span><span style=3D"font-size:10.0pt;font-fa=
mily:"Courier New";color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#880000">//implementation</span></span><span style=3D"font-size=
:10.0pt;font-family:"Courier New";color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#666600">}</span></span><span style=3D"font-size:10.0pt;font-fa=
mily:"Courier New""><u></u><u></u></span></p>
</div>
</div>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt"><br>
<br>
OK, fine.<br>
<br>
I've also been told about a different class of functions: template func=
tions. For reasons I haven't been told and don't much care about (s=
ince I'm a novice), I have to put the implementation in the header file=
.. So I know that if I type the word "template",
then that function's implementation has to go into a header. So I alwa=
ys do this:<u></u><u></u></p>
<div style=3D"border:solid #bbbbbb 1.0pt;padding:0in 0in 0in 0in;word-wrap:=
break-word">
<div>
<p class=3D"MsoNormal" style=3D"background:#fafafa"><span><span style=3D"fo=
nt-size:10.0pt;font-family:"Courier New";color:#880000">//header<=
/span></span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#000088">template</span></span><span><span style=3D"font-size:1=
0.0pt;font-family:"Courier New";color:#666600"><</span></span>=
<span><span style=3D"font-size:10.0pt;font-family:"Courier New";c=
olor:#000088">typename</span></span><span><span style=3D"font-size:10.0pt;f=
ont-family:"Courier New";color:black">
T</span></span><span><span style=3D"font-size:10.0pt;font-family:"Cou=
rier New";color:#666600">></span></span><span style=3D"font-size:10=
..0pt;font-family:"Courier New";color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#660066">RetType</span></span><span><span style=3D"font-size:10=
..0pt;font-family:"Courier New";color:black"> func_name_template</=
span></span><span><span style=3D"font-size:10.0pt;font-family:"Courier=
New";color:#666600">(</span></span><span><span style=3D"font-size:10.=
0pt;font-family:"Courier New";color:black">T
arg1</span></span><span><span style=3D"font-size:10.0pt;font-family:"=
Courier New";color:#666600">,</span></span><span><span style=3D"font-s=
ize:10.0pt;font-family:"Courier New";color:black">
</span></span><span><span style=3D"font-size:10.0pt;font-family:"Couri=
er New";color:#666600">...)</span></span><span style=3D"font-size:10.0=
pt;font-family:"Courier New";color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#666600">{</span></span><span style=3D"font-size:10.0pt;font-fa=
mily:"Courier New";color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#880000">//implementation</span></span><span style=3D"font-size=
:10.0pt;font-family:"Courier New";color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#666600">}</span></span><span style=3D"font-size:10.0pt;font-fa=
mily:"Courier New";color:black"><br>
<br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#880000">//source doesn't exist.</span></span><span style=
=3D"font-size:10.0pt;font-family:"Courier New""><u></u><u></u></s=
pan></p>
</div>
</div>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt"><br>
=C2=A0<br>
OK, fine. So... explain to me, the novice C++ programmer, why this doesn=
9;t work:<u></u><u></u></p>
<div style=3D"border:solid #bbbbbb 1.0pt;padding:0in 0in 0in 0in;word-wrap:=
break-word">
<div>
<p class=3D"MsoNormal" style=3D"background:#fafafa"><span><span style=3D"fo=
nt-size:10.0pt;font-family:"Courier New";color:#880000">//header<=
/span></span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#660066">RetType</span></span><span><span style=3D"font-size:10=
..0pt;font-family:"Courier New";color:black"> func_name_concept</s=
pan></span><span><span style=3D"font-size:10.0pt;font-family:"Courier =
New";color:#666600">(</span></span><span><span style=3D"font-size:10.0=
pt;font-family:"Courier New";color:#660066">ConceptName</span></s=
pan><span><span style=3D"font-size:10.0pt;font-family:"Courier New&quo=
t;;color:black">
arg1</span></span><span><span style=3D"font-size:10.0pt;font-family:"=
Courier New";color:#666600">,</span></span><span><span style=3D"font-s=
ize:10.0pt;font-family:"Courier New";color:black">
</span></span><span><span style=3D"font-size:10.0pt;font-family:"Couri=
er New";color:#666600">...);</span></span><span style=3D"font-size:10.=
0pt;font-family:"Courier New";color:black"><br>
<br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#880000">//source</span></span><span style=3D"font-size:10.0pt;=
font-family:"Courier New";color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#660066">RetType</span></span><span><span style=3D"font-size:10=
..0pt;font-family:"Courier New";color:black"> func_name_concept</s=
pan></span><span><span style=3D"font-size:10.0pt;font-family:"Courier =
New";color:#666600">(</span></span><span><span style=3D"font-size:10.0=
pt;font-family:"Courier New";color:#660066">ConceptName</span></s=
pan><span><span style=3D"font-size:10.0pt;font-family:"Courier New&quo=
t;;color:black">
arg1</span></span><span><span style=3D"font-size:10.0pt;font-family:"=
Courier New";color:#666600">,</span></span><span><span style=3D"font-s=
ize:10.0pt;font-family:"Courier New";color:black">
</span></span><span><span style=3D"font-size:10.0pt;font-family:"Couri=
er New";color:#666600">...)</span></span><span style=3D"font-size:10.0=
pt;font-family:"Courier New";color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#666600">{</span></span><span style=3D"font-size:10.0pt;font-fa=
mily:"Courier New";color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#880000">//implementation</span></span><span style=3D"font-size=
:10.0pt;font-family:"Courier New";color:black"><br>
</span><span><span style=3D"font-size:10.0pt;font-family:"Courier New&=
quot;;color:#666600">}</span></span><span style=3D"font-size:10.0pt;font-fa=
mily:"Courier New""><u></u><u></u></span></p>
</div>
</div>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt"><br>
Explain to me, the novice C++ programmer, why this thing which doesn't =
look like a template suddenly
<i>became</i> a template. Explain to me why I have to implement it in a hea=
der, even though it looks exactly like every other non-template function de=
claration/definition.<br>
<br>
To the novice C++ programmer, it <i>isn't</i> "all just programmin=
g." Whether something is a template
<i>matters</i>.<br>
<br>
Oh, you could say, "well just put <i>everything</i> in a header."=
That's... insane. Compile times for C++ projects of significant size a=
re already huge even when you try to only put what you need in headers. Add=
ing the burden of shoving everything in a header
is crazy.<br>
<br>
Now, if you can promise me that the same version of C++ that will include t=
his terse syntax will also include
<i>modules</i>, I will immediately stop caring. Once that exists, then most=
of the differences between template and non-template functions will be era=
sed. And therefore, so too can the syntactic differences.<br>
<br>
But so long as there is a difference in how you implement template and non-=
template functions, I say that there should be an obvious difference in syn=
tax too.<u></u><u></u></p>
</div>
<blockquote style=3D"border:none;border-left:solid #cccccc 1.0pt;padding:0i=
n 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">>
</span>My issue is with, well, any syntax that declares a template without =
having to type either the word "template" or the use of "<=
;>" brackets.<u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">That ship has sailed:</span><u></u><u=
></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto plus =3D [](aut=
o x, auto y) { return x+y; }</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">which even already decays to an ordin=
ary pointer to function, etc.</span><u></u><u></u></p>
</div>
</div>
</blockquote>
<div>
<p class=3D"MsoNormal"><br>
That doesn't decay into a function pointer. It can't; the operator(=
) is a template.<br>
=C2=A0<u></u><u></u></p>
</div>
<blockquote style=3D"border:none;border-left:solid #cccccc 1.0pt;padding:0i=
n 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">Clarifying Q: Are we mainly arguing a=
bout whether to require the three characters =3D, [, and ] ?</span><u></u><=
u></u></p>
</div>
</div>
</blockquote>
<div>
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt">Except that there is =
a difference between creating a lambda (which creates a functor) and creati=
ng a function (which can be overloaded).<u></u><u></u></p>
</div>
<blockquote style=3D"border:none;border-left:solid #cccccc 1.0pt;padding:0i=
n 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">Not only has the ship sailed, but I f=
or one like the direction it=E2=80=99s sailing. I see no reason why functio=
ns
should be forced to spell =E2=80=9Ctemplate=E2=80=9D and =E2=80=9C<>=
=E2=80=9D. What value does it add? It=E2=80=99s =E2=80=9Cjust programming.=
=E2=80=9D In fact, if we didn=E2=80=99t have backward compatibility issues =
with unnamed parameters and such, I=E2=80=99d personally probably be fine w=
ith just =E2=80=9Cauto plus(x,y){x+y}=E2=80=9D as an
equivalent function definition. That still doesn=E2=80=99t lose any inform=
ation.</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">Gratuitous syntax is often unnecessar=
y and usually harmful. Saying</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 template<class T,=
class U></span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto(T x, U y) ->=
decltype(x+y) { return x+y; }</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">does not appear to me to contain any =
more information than</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto plus(auto x, au=
to y) { return x+y; }</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">does it?</span><u></u><u></u></p>
</div>
</div>
</blockquote>
<div>
<p class=3D"MsoNormal">If you take out the late specified return type (I sp=
ecifically said that static deduction was fine), then I don't see the p=
roblem with the first one.<br>
<br>
=C2=A0<u></u><u></u></p>
</div>
<blockquote style=3D"border:none;border-left:solid #cccccc 1.0pt;padding:0i=
n 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">Requiring the verbose syntax is gratu=
itous, if the verbose syntax does not add information, does not
serve to disambiguate anything, and does not highlight a dangerous operati=
on or anything else I can see that deserves to have attention called to it.=
</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">There=E2=80=99s a disturbing (to me a=
nd at least some others) trend in C++ these days: People seem to be very
prone to wanting =E2=80=9Cmore syntax=E2=80=9D lately. It=E2=80=99s rather=
Vasa-like, if only lexically. Let me channel certain influential committee=
members and say: =E2=80=98People these days are always asking for more syn=
tax! There=E2=80=99s no proposal they=E2=80=99ve seen that they couldn=E2=
=80=99t make uglier
with more syntax!=E2=80=99</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">Important note: The point here is NOT=
terseness for terseness=E2=80=99 sake. I am not arguing that terser is
somehow better, that terseness is virtuous in itself. Too many people glor=
ify languages because they=E2=80=99re terser; fewer characters alone doesn=
=E2=80=99t make code clearer. Rather, my point is to avoid gratuitous verbo=
sity. At the other end of the pendulum, too many
people glorify verbose syntax because they think _that_ is somehow inheren=
tly clearer; usually it isn=E2=80=99t. So I am arguing that neither is verb=
osity virtuous in itself.</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0</span><u></u><u></u></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">Herb</span><u></u><u></u></p>
</div>
</div>
</blockquote>
<div>
<p class=3D"MsoNormal">The virtue to me of the large syntax of templates is=
this:<br>
<br>
Templates have to be treated differently from non-templates. They have diff=
erent needs of where their implementations live. And because of those needs=
, templates make your code compile slower. Even ignoring the compile-time c=
ost of template instantiation, your
source has to go in the header. And if that header is included in more tha=
n one place, then the source for that template must be recompiled for every=
place it is included.<br>
<br>
Therefore, the bulky template syntax pokes you in the eye every time you wr=
ite something that's going to compile slower. It immediately lets you k=
now that this function operates under fundamentally different rules than re=
gular functions.<br>
<br>
Again, if you could guarantee that we get modules alongside this syntax, I&=
#39;d be fine, since using templates will not hurt your compile times nearl=
y as much.<u></u><u></u></p>
</div>
<p class=3D"MsoNormal"><u></u>=C2=A0<u></u></p>
</div>
</div></div></div>
</div>
</div>
</blockquote></div><br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Discussion" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-discussion+unsubscribe@isocpp.org">std-discus=
sion+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-discussion@isocp=
p.org">std-discussion@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-discussion/">http://groups.google.com/a/isocpp.org/group/std-discussion=
/</a>.<br />
--001a1147b5766b7da70510a3acae--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Fri, 6 Mar 2015 12:11:39 -0800 (PST)
Raw View
------=_Part_812_1566648847.1425672699810
Content-Type: multipart/alternative;
boundary="----=_Part_813_370175662.1425672699810"
------=_Part_813_370175662.1425672699810
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Friday, March 6, 2015 at 2:27:23 PM UTC-5, Geoffrey Romer wrote:
>
>
> On Fri, Mar 6, 2015 at 10:27 AM, Herb Sutter <hsu...@microsoft.com=20
> <javascript:>> wrote:
>
>> > To the novice C++ programmer, it *isn't* "all just programming."=20
>> Whether something is a template *matters*.
>>
>> =20
>>
>> Why? Only because of where you put the definition, and that=E2=80=99s (a=
)=20
>> teachable and (b) not new because the same issue exists already with:
>>
>> =20
>>
>> auto f() { =E2=80=A6 };
>>
>> =20
>>
>> This is not a template, but must appear in a header. This is amazingly=
=20
>> similar =E2=80=93 and easy to teach as =E2=80=9Cif the declaration menti=
ons =E2=80=98auto=E2=80=99 or a=20
>> concept name, the compiler needs the definition, either to deduce someth=
ing=20
>> or to inline the body into the caller.=E2=80=9D Right?
>>
>> =20
>>
>> Herb
>>
>> =20
>>
>> PS =E2=80=93 Since you mention =E2=80=9Cnovices=E2=80=9D writing templat=
es, in my experience (and=20
>> to my surprise) I=E2=80=99ve found that not only novices but also interm=
ediate=20
>> developers (like 5-7 year veterans) don=E2=80=99t write templates very m=
uch. [I=20
>> expect this to change with concepts, for the good.] I discovered this by=
=20
>> chance when I had a class exercise that included writing a very simple=
=20
>> template, and as I walked through the class during the exercise I was=20
>> surprised that most of the groups asked about the syntax for writing a=
=20
>> template =E2=80=93 a dead giveaway that they didn=E2=80=99t write templa=
tes very often, yet=20
>> these were pretty experienced developers who used C++ every day, but jus=
t=20
>> never needed to write templates much in their normal code. To validate t=
hat=20
>> this wasn=E2=80=99t just an outlier group, I=E2=80=99ve watched that exe=
rcise in a number=20
>> of classes over several years and found a similar result =E2=80=93 the m=
ajority of=20
>> even reasonably experienced C++ programmers asked about the syntax for h=
ow=20
>> to write a template.
>>
>
> This very much matches my experience- as far as I can tell, the vast=20
> majority of C++ code is non-template code. But why is that surprising, an=
d=20
> why do you expect concepts to change it?
>
>
That's my experience as well. However, I can also say that concepts is not=
=20
what would get me to write more templates, as concepts (as it is currently=
=20
proposed) only makes *using* templates easier (by declaring up-front what=
=20
the requirements are). It doesn't make implementing a function easier (by=
=20
checking each point of use to see if it is a required behavior).
Even with that, it wouldn't make me write more templates. I'd still need=20
modules for that; compile times are just too long for heavily templated=20
code. Debugging and testing requires lots of compilation, so things that=20
make compilation slower will (continue to) be avoided.
I just wish I didn't have to avoid useful language features because of the=
=20
compilation mechanism.
--=20
---=20
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 e=
mail 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-discuss=
ion/.
------=_Part_813_370175662.1425672699810
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Friday, March 6, 2015 at 2:27:23 PM UTC-5, Geof=
frey Romer wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr"><div><br><div class=3D"gmail_quote">On Fri, Mar 6, 2015 at 10:27 AM, He=
rb Sutter <span dir=3D"ltr"><<a href=3D"javascript:" target=3D"_blank" g=
df-obfuscated-mailto=3D"SOUPb3HgnA0J" rel=3D"nofollow" onmousedown=3D"this.=
href=3D'javascript:';return true;" onclick=3D"this.href=3D'javascript:';ret=
urn true;">hsu...@microsoft.com</a>></span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">
<div link=3D"#0563C1" vlink=3D"#954F72" lang=3D"EN-US">
<div><span>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">></span> To the novice C++ program=
mer, it
<i>isn't</i> "all just programming." Whether something is a template <i>mat=
ters</i>.<span style=3D"font-size:11.0pt;font-family:"Calibri",sa=
ns-serif;color:#1f497d"><u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
</span><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&=
quot;Calibri",sans-serif;color:#1f497d">Why? Only because of where you=
put the definition, and that=E2=80=99s (a) teachable and (b) not new becau=
se the same issue exists already with:<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"> &=
nbsp; auto f() { =E2=80=A6 =
};<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">This is not a template, but must appe=
ar in a header. This is amazingly similar =E2=80=93 and easy to teach as =
=E2=80=9Cif the declaration mentions =E2=80=98auto=E2=80=99 or a concept na=
me, the
compiler needs the definition, either to deduce something or to inline the=
body into the caller.=E2=80=9D Right?<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">Herb<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">PS =E2=80=93 Since you mention =E2=80=
=9Cnovices=E2=80=9D writing templates, in my experience (and to my surprise=
) I=E2=80=99ve found that not only novices but also intermediate developers=
(like
5-7 year veterans) don=E2=80=99t write templates very much. [I expect this=
to change with concepts, for the good.] I discovered this by chance when I=
had a class exercise that included writing a very simple template, and as =
I walked through the class during the exercise
I was surprised that most of the groups asked about the syntax for writing=
a template =E2=80=93 a dead giveaway that they didn=E2=80=99t write templa=
tes very often, yet these were pretty experienced developers who used C++ e=
very day, but just never needed to write templates
much in their normal code. To validate that this wasn=E2=80=99t just an ou=
tlier group, I=E2=80=99ve watched that exercise in a number of classes over=
several years and found a similar result =E2=80=93 the majority of even re=
asonably experienced C++ programmers asked about the syntax
for how to write a template.</span></p></div></div></blockquote><div><br><=
/div><div>This very much matches my experience- as far as I can tell, the v=
ast majority of C++ code is non-template code. But why is that surprising, =
and why do you expect concepts to change it?<br></div></div><br></div></div=
></blockquote><div><br>That's my experience as well. However, I can also sa=
y that concepts is not what would get me to write more templates, as concep=
ts (as it is currently proposed) only makes <i>using</i> templates easier (=
by declaring up-front what the requirements are). It doesn't make implement=
ing a function easier (by checking each point of use to see if it is a requ=
ired behavior).<br><br>Even with that, it wouldn't make me write more templ=
ates. I'd still need modules for that; compile times are just too long for =
heavily templated code. Debugging and testing requires lots of compilation,=
so things that make compilation slower will (continue to) be avoided.<br><=
br>I just wish I didn't have to avoid useful language features because of t=
he compilation mechanism.<br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Discussion" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-discussion+unsubscribe@isocpp.org">std-discus=
sion+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-discussion@isocp=
p.org">std-discussion@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-discussion/">http://groups.google.com/a/isocpp.org/group/std-discussion=
/</a>.<br />
------=_Part_813_370175662.1425672699810--
------=_Part_812_1566648847.1425672699810--
.
Author: "'Geoffrey Romer' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Fri, 6 Mar 2015 13:25:49 -0800
Raw View
--001a11c11de60fe4940510a554b7
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Fri, Mar 6, 2015 at 12:11 PM, Nicol Bolas <jmckesson@gmail.com> wrote:
>
>
> On Friday, March 6, 2015 at 2:27:23 PM UTC-5, Geoffrey Romer wrote:
>>
>>
>> On Fri, Mar 6, 2015 at 10:27 AM, Herb Sutter <hsu...@microsoft.com>
>> wrote:
>>
>>> > To the novice C++ programmer, it *isn't* "all just programming."
>>> Whether something is a template *matters*.
>>>
>>>
>>>
>>> Why? Only because of where you put the definition, and that=E2=80=99s (=
a)
>>> teachable and (b) not new because the same issue exists already with:
>>>
>>>
>>>
>>> auto f() { =E2=80=A6 };
>>>
>>>
>>>
>>> This is not a template, but must appear in a header. This is amazingly
>>> similar =E2=80=93 and easy to teach as =E2=80=9Cif the declaration ment=
ions =E2=80=98auto=E2=80=99 or a
>>> concept name, the compiler needs the definition, either to deduce somet=
hing
>>> or to inline the body into the caller.=E2=80=9D Right?
>>>
>>>
>>>
>>> Herb
>>>
>>>
>>>
>>> PS =E2=80=93 Since you mention =E2=80=9Cnovices=E2=80=9D writing templa=
tes, in my experience
>>> (and to my surprise) I=E2=80=99ve found that not only novices but also =
intermediate
>>> developers (like 5-7 year veterans) don=E2=80=99t write templates very =
much. [I
>>> expect this to change with concepts, for the good.] I discovered this b=
y
>>> chance when I had a class exercise that included writing a very simple
>>> template, and as I walked through the class during the exercise I was
>>> surprised that most of the groups asked about the syntax for writing a
>>> template =E2=80=93 a dead giveaway that they didn=E2=80=99t write templ=
ates very often, yet
>>> these were pretty experienced developers who used C++ every day, but ju=
st
>>> never needed to write templates much in their normal code. To validate =
that
>>> this wasn=E2=80=99t just an outlier group, I=E2=80=99ve watched that ex=
ercise in a number
>>> of classes over several years and found a similar result =E2=80=93 the =
majority of
>>> even reasonably experienced C++ programmers asked about the syntax for =
how
>>> to write a template.
>>>
>>
>> This very much matches my experience- as far as I can tell, the vast
>> majority of C++ code is non-template code. But why is that surprising, a=
nd
>> why do you expect concepts to change it?
>>
>>
> That's my experience as well. However, I can also say that concepts is no=
t
> what would get me to write more templates, as concepts (as it is currentl=
y
> proposed) only makes *using* templates easier (by declaring up-front what
> the requirements are). It doesn't make implementing a function easier (by
> checking each point of use to see if it is a required behavior).
>
Interesting; my impression was the other way around, that concepts make it
easier to write templates, but not really easier to use them. The main
functional advantage that I see with concepts is that they let you control
the overload set much more easily (and much more readably), and that helps
template authors, not template users. I see your point about declaring the
requirements up-front, but decent template libraries already do that in the
documentation; I'm not sure that formalizing those requirements in code
will really help users much.
Even with that, it wouldn't make me write more templates. I'd still need
> modules for that; compile times are just too long for heavily templated
> code. Debugging and testing requires lots of compilation, so things that
> make compilation slower will (continue to) be avoided.
>
> I just wish I didn't have to avoid useful language features because of th=
e
> compilation mechanism.
>
--=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/.
--001a11c11de60fe4940510a554b7
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">=
On Fri, Mar 6, 2015 at 12:11 PM, Nicol Bolas <span dir=3D"ltr"><<a href=
=3D"mailto:jmckesson@gmail.com" target=3D"_blank">jmckesson@gmail.com</a>&g=
t;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><br><br=
>On Friday, March 6, 2015 at 2:27:23 PM UTC-5, Geoffrey Romer wrote:<span c=
lass=3D""><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"><div><br=
><div class=3D"gmail_quote">On Fri, Mar 6, 2015 at 10:27 AM, Herb Sutter <s=
pan dir=3D"ltr"><<a rel=3D"nofollow">hsu...@microsoft.com</a>></span>=
wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bor=
der-left:1px #ccc solid;padding-left:1ex">
<div link=3D"#0563C1" vlink=3D"#954F72" lang=3D"EN-US">
<div><span>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">></span> To the novice C++ program=
mer, it
<i>isn't</i> "all just programming." Whether something is a t=
emplate <i>matters</i>.<span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
</span><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&=
quot;Calibri",sans-serif;color:#1f497d">Why? Only because of where you=
put the definition, and that=E2=80=99s (a) teachable and (b) not new becau=
se the same issue exists already with:<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto f() { =E2=80=A6=
};<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">This is not a template, but must appe=
ar in a header. This is amazingly similar =E2=80=93 and easy to teach as =
=E2=80=9Cif the declaration mentions =E2=80=98auto=E2=80=99 or a concept na=
me, the
compiler needs the definition, either to deduce something or to inline the=
body into the caller.=E2=80=9D Right?<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">Herb<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">PS =E2=80=93 Since you mention =E2=80=
=9Cnovices=E2=80=9D writing templates, in my experience (and to my surprise=
) I=E2=80=99ve found that not only novices but also intermediate developers=
(like
5-7 year veterans) don=E2=80=99t write templates very much. [I expect this=
to change with concepts, for the good.] I discovered this by chance when I=
had a class exercise that included writing a very simple template, and as =
I walked through the class during the exercise
I was surprised that most of the groups asked about the syntax for writing=
a template =E2=80=93 a dead giveaway that they didn=E2=80=99t write templa=
tes very often, yet these were pretty experienced developers who used C++ e=
very day, but just never needed to write templates
much in their normal code. To validate that this wasn=E2=80=99t just an ou=
tlier group, I=E2=80=99ve watched that exercise in a number of classes over=
several years and found a similar result =E2=80=93 the majority of even re=
asonably experienced C++ programmers asked about the syntax
for how to write a template.</span></p></div></div></blockquote><div><br><=
/div><div>This very much matches my experience- as far as I can tell, the v=
ast majority of C++ code is non-template code. But why is that surprising, =
and why do you expect concepts to change it?<br></div></div><br></div></div=
></blockquote></span><div><br>That's my experience as well. However, I =
can also say that concepts is not what would get me to write more templates=
, as concepts (as it is currently proposed) only makes <i>using</i> templat=
es easier (by declaring up-front what the requirements are). It doesn't=
make implementing a function easier (by checking each point of use to see =
if it is a required behavior).<br></div></div></blockquote><div><br></div><=
div>Interesting; my impression was the other way around, that concepts make=
it easier to write templates, but not really easier to use them. The main =
functional advantage that I see with concepts is that they let you control =
the overload set much more easily (and much more readably), and that helps =
template authors, not template users. I see your point about declaring the =
requirements up-front, but decent template libraries already do that in the=
documentation; I'm not sure that formalizing those requirements in cod=
e will really help users much.</div><div><br></div><blockquote class=3D"gma=
il_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-lef=
t:1ex"><div dir=3D"ltr"><div>Even with that, it wouldn't make me write =
more templates. I'd still need modules for that; compile times are just=
too long for heavily templated code. Debugging and testing requires lots o=
f compilation, so things that make compilation slower will (continue to) be=
avoided.<br><br>I just wish I didn't have to avoid useful language fea=
tures because of the compilation mechanism.<br></div></div></blockquote></d=
iv><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 />
--001a11c11de60fe4940510a554b7--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Fri, 6 Mar 2015 14:23:17 -0800 (PST)
Raw View
------=_Part_1288_945929955.1425680597756
Content-Type: multipart/alternative;
boundary="----=_Part_1289_423314944.1425680597757"
------=_Part_1289_423314944.1425680597757
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Friday, March 6, 2015 at 4:25:51 PM UTC-5, Geoffrey Romer wrote:
>
>
> On Fri, Mar 6, 2015 at 12:11 PM, Nicol Bolas <jmck...@gmail.com=20
> <javascript:>> wrote:
>
>>
>>
>> On Friday, March 6, 2015 at 2:27:23 PM UTC-5, Geoffrey Romer wrote:
>>>
>>>
>>> On Fri, Mar 6, 2015 at 10:27 AM, Herb Sutter <hsu...@microsoft.com>=20
>>> wrote:
>>>
>>>> > To the novice C++ programmer, it *isn't* "all just programming."=20
>>>> Whether something is a template *matters*.
>>>>
>>>> =20
>>>>
>>>> Why? Only because of where you put the definition, and that=E2=80=99s =
(a)=20
>>>> teachable and (b) not new because the same issue exists already with:
>>>>
>>>> =20
>>>>
>>>> auto f() { =E2=80=A6 };
>>>>
>>>> =20
>>>>
>>>> This is not a template, but must appear in a header. This is amazingly=
=20
>>>> similar =E2=80=93 and easy to teach as =E2=80=9Cif the declaration men=
tions =E2=80=98auto=E2=80=99 or a=20
>>>> concept name, the compiler needs the definition, either to deduce some=
thing=20
>>>> or to inline the body into the caller.=E2=80=9D Right?
>>>>
>>>> =20
>>>>
>>>> Herb
>>>>
>>>> =20
>>>>
>>>> PS =E2=80=93 Since you mention =E2=80=9Cnovices=E2=80=9D writing templ=
ates, in my experience=20
>>>> (and to my surprise) I=E2=80=99ve found that not only novices but also=
intermediate=20
>>>> developers (like 5-7 year veterans) don=E2=80=99t write templates very=
much. [I=20
>>>> expect this to change with concepts, for the good.] I discovered this =
by=20
>>>> chance when I had a class exercise that included writing a very simple=
=20
>>>> template, and as I walked through the class during the exercise I was=
=20
>>>> surprised that most of the groups asked about the syntax for writing a=
=20
>>>> template =E2=80=93 a dead giveaway that they didn=E2=80=99t write temp=
lates very often, yet=20
>>>> these were pretty experienced developers who used C++ every day, but j=
ust=20
>>>> never needed to write templates much in their normal code. To validate=
that=20
>>>> this wasn=E2=80=99t just an outlier group, I=E2=80=99ve watched that e=
xercise in a number=20
>>>> of classes over several years and found a similar result =E2=80=93 the=
majority of=20
>>>> even reasonably experienced C++ programmers asked about the syntax for=
how=20
>>>> to write a template.
>>>>
>>>
>>> This very much matches my experience- as far as I can tell, the vast=20
>>> majority of C++ code is non-template code. But why is that surprising, =
and=20
>>> why do you expect concepts to change it?
>>>
>>>
>> That's my experience as well. However, I can also say that concepts is=
=20
>> not what would get me to write more templates, as concepts (as it is=20
>> currently proposed) only makes *using* templates easier (by declaring=20
>> up-front what the requirements are). It doesn't make implementing a=20
>> function easier (by checking each point of use to see if it is a require=
d=20
>> behavior).
>>
>
> Interesting; my impression was the other way around, that concepts make i=
t=20
> easier to write templates, but not really easier to use them. The main=20
> functional advantage that I see with concepts is that they let you contro=
l=20
> the overload set much more easily (and much more readably), and that help=
s=20
> template authors, not template users. I see your point about declaring th=
e=20
> requirements up-front, but decent template libraries already do that in t=
he=20
> documentation; I'm not sure that formalizing those requirements in code=
=20
> will really help users much.
>
You assume that users actually read that documentation. Or remember it when=
=20
they read it.
If someone gives you an abstract base class to implement, the requirements=
=20
are listed right there, in the language. You have to derive from that=20
class; derive from the wrong one, and you'll get a compiler error=20
somewhere. You have to override all pure-virtual methods; type the method=
=20
name wrong, and you get a compiler error somewhere (either due to the class=
=20
still being abstract or because you used "override" and there was no base=
=20
class function). And so forth.
If I give a non-moveable type to std::vector<T>, it will give me some kind=
=20
of compiler error. What kind? God only knows, but more likely than not, it=
=20
will be long, obtuse, and generally indecipherable if you've never seen it=
=20
before. This is because the compilation failure happens somewhere in the=20
instantiation of std::vector<T> when it tries to actually use your type in=
=20
a way that it can't be used. So the compiler will point to the guts of=20
std::vector<T>'s implementation, rather than at your code where the actual=
=20
mistake was made.
If I give a non-moveable type to std::vector<MoveConstructable>, it will=20
give me a much cleaner error message. With a semi-decent compiler, it'll=20
point you right to the line where you instantiated your std::vector and say=
=20
"Hey, your type T isn't MoveConstructable, because it doesn't have a move=
=20
constructor." At the very least, I won't get a giant spew of template stuff=
..
Concepts are great at telling me what I did wrong when I misuse a template.=
=20
Which means I will feel much more confident that, if it compiled, I'm using=
=20
the template correctly.
--=20
---=20
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 e=
mail 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-discuss=
ion/.
------=_Part_1289_423314944.1425680597757
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Friday, March 6, 2015 at 4:25:51 PM UTC-5, Geof=
frey Romer wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr"><div><br><div class=3D"gmail_quote">On Fri, Mar 6, 2015 at 12:11 PM, Ni=
col Bolas <span dir=3D"ltr"><<a href=3D"javascript:" target=3D"_blank" g=
df-obfuscated-mailto=3D"lOH0lMddftIJ" rel=3D"nofollow" onmousedown=3D"this.=
href=3D'javascript:';return true;" onclick=3D"this.href=3D'javascript:';ret=
urn true;">jmck...@gmail.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"><div dir=3D"ltr"><br><br>On Friday, March 6, 2015 at 2:27:23 PM U=
TC-5, Geoffrey Romer wrote:<span><blockquote class=3D"gmail_quote" style=3D=
"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><d=
iv dir=3D"ltr"><div><br><div class=3D"gmail_quote">On Fri, Mar 6, 2015 at 1=
0:27 AM, Herb Sutter <span dir=3D"ltr"><<a rel=3D"nofollow">hsu...@micro=
soft.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">
<div link=3D"#0563C1" vlink=3D"#954F72" lang=3D"EN-US">
<div><span>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">></span> To the novice C++ program=
mer, it
<i>isn't</i> "all just programming." Whether something is a template <i>mat=
ters</i>.<span style=3D"font-size:11.0pt;font-family:"Calibri",sa=
ns-serif;color:#1f497d"><u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
</span><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&=
quot;Calibri",sans-serif;color:#1f497d">Why? Only because of where you=
put the definition, and that=E2=80=99s (a) teachable and (b) not new becau=
se the same issue exists already with:<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"> &=
nbsp; auto f() { =E2=80=A6 =
};<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">This is not a template, but must appe=
ar in a header. This is amazingly similar =E2=80=93 and easy to teach as =
=E2=80=9Cif the declaration mentions =E2=80=98auto=E2=80=99 or a concept na=
me, the
compiler needs the definition, either to deduce something or to inline the=
body into the caller.=E2=80=9D Right?<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">Herb<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">PS =E2=80=93 Since you mention =E2=80=
=9Cnovices=E2=80=9D writing templates, in my experience (and to my surprise=
) I=E2=80=99ve found that not only novices but also intermediate developers=
(like
5-7 year veterans) don=E2=80=99t write templates very much. [I expect this=
to change with concepts, for the good.] I discovered this by chance when I=
had a class exercise that included writing a very simple template, and as =
I walked through the class during the exercise
I was surprised that most of the groups asked about the syntax for writing=
a template =E2=80=93 a dead giveaway that they didn=E2=80=99t write templa=
tes very often, yet these were pretty experienced developers who used C++ e=
very day, but just never needed to write templates
much in their normal code. To validate that this wasn=E2=80=99t just an ou=
tlier group, I=E2=80=99ve watched that exercise in a number of classes over=
several years and found a similar result =E2=80=93 the majority of even re=
asonably experienced C++ programmers asked about the syntax
for how to write a template.</span></p></div></div></blockquote><div><br><=
/div><div>This very much matches my experience- as far as I can tell, the v=
ast majority of C++ code is non-template code. But why is that surprising, =
and why do you expect concepts to change it?<br></div></div><br></div></div=
></blockquote></span><div><br>That's my experience as well. However, I can =
also say that concepts is not what would get me to write more templates, as=
concepts (as it is currently proposed) only makes <i>using</i> templates e=
asier (by declaring up-front what the requirements are). It doesn't make im=
plementing a function easier (by checking each point of use to see if it is=
a required behavior).<br></div></div></blockquote><div><br></div><div>Inte=
resting; my impression was the other way around, that concepts make it easi=
er to write templates, but not really easier to use them. The main function=
al advantage that I see with concepts is that they let you control the over=
load set much more easily (and much more readably), and that helps template=
authors, not template users. I see your point about declaring the requirem=
ents up-front, but decent template libraries already do that in the documen=
tation; I'm not sure that formalizing those requirements in code will reall=
y help users much.</div></div></div></div></blockquote><div><br>You assume =
that users actually read that documentation. Or remember it when they read =
it.<br><br>If someone gives you an abstract base class to implement, the re=
quirements are listed right there, in the language. You have to derive from=
that class; derive from the wrong one, and you'll get a compiler error som=
ewhere. You have to override all pure-virtual methods; type the method name=
wrong, and you get a compiler error somewhere (either due to the class sti=
ll being abstract or because you used "override" and there was no base clas=
s function). And so forth.<br><br>If I give a non-moveable type to std::vec=
tor<T>, it will give me some kind of compiler error. What kind? God o=
nly knows, but more likely than not, it will be long, obtuse, and generally=
indecipherable if you've never seen it before. This is because the compila=
tion failure happens somewhere in the instantiation of std::vector<T>=
when it tries to actually use your type in a way that it can't be used. So=
the compiler will point to the guts of std::vector<T>'s implementati=
on, rather than at your code where the actual mistake was made.<br><br>If I=
give a non-moveable type to std::vector<MoveConstructable>, it will =
give me a much cleaner error message. With a semi-decent compiler, it'll po=
int you right to the line where you instantiated your std::vector and say "=
Hey, your type T isn't MoveConstructable, because it doesn't have a move co=
nstructor." At the very least, I won't get a giant spew of template stuff.<=
br><br>Concepts are great at telling me what I did wrong when I misuse a te=
mplate. Which means I will feel much more confident that, if it compiled, I=
'm using the template correctly.<br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Discussion" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-discussion+unsubscribe@isocpp.org">std-discus=
sion+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-discussion@isocp=
p.org">std-discussion@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-discussion/">http://groups.google.com/a/isocpp.org/group/std-discussion=
/</a>.<br />
------=_Part_1289_423314944.1425680597757--
------=_Part_1288_945929955.1425680597756--
.
Author: "'Geoffrey Romer' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Fri, 6 Mar 2015 16:33:33 -0800
Raw View
--001a113506b87925820510a7f390
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Fri, Mar 6, 2015 at 2:23 PM, Nicol Bolas <jmckesson@gmail.com> wrote:
>
>
> On Friday, March 6, 2015 at 4:25:51 PM UTC-5, Geoffrey Romer wrote:
>>
>>
>> On Fri, Mar 6, 2015 at 12:11 PM, Nicol Bolas <jmck...@gmail.com> wrote:
>>
>>>
>>>
>>> On Friday, March 6, 2015 at 2:27:23 PM UTC-5, Geoffrey Romer wrote:
>>>>
>>>>
>>>> On Fri, Mar 6, 2015 at 10:27 AM, Herb Sutter <hsu...@microsoft.com>
>>>> wrote:
>>>>
>>>>> > To the novice C++ programmer, it *isn't* "all just programming."
>>>>> Whether something is a template *matters*.
>>>>>
>>>>>
>>>>>
>>>>> Why? Only because of where you put the definition, and that=E2=80=99s=
(a)
>>>>> teachable and (b) not new because the same issue exists already with:
>>>>>
>>>>>
>>>>>
>>>>> auto f() { =E2=80=A6 };
>>>>>
>>>>>
>>>>>
>>>>> This is not a template, but must appear in a header. This is amazingl=
y
>>>>> similar =E2=80=93 and easy to teach as =E2=80=9Cif the declaration me=
ntions =E2=80=98auto=E2=80=99 or a
>>>>> concept name, the compiler needs the definition, either to deduce som=
ething
>>>>> or to inline the body into the caller.=E2=80=9D Right?
>>>>>
>>>>>
>>>>>
>>>>> Herb
>>>>>
>>>>>
>>>>>
>>>>> PS =E2=80=93 Since you mention =E2=80=9Cnovices=E2=80=9D writing temp=
lates, in my experience
>>>>> (and to my surprise) I=E2=80=99ve found that not only novices but als=
o intermediate
>>>>> developers (like 5-7 year veterans) don=E2=80=99t write templates ver=
y much. [I
>>>>> expect this to change with concepts, for the good.] I discovered this=
by
>>>>> chance when I had a class exercise that included writing a very simpl=
e
>>>>> template, and as I walked through the class during the exercise I was
>>>>> surprised that most of the groups asked about the syntax for writing =
a
>>>>> template =E2=80=93 a dead giveaway that they didn=E2=80=99t write tem=
plates very often, yet
>>>>> these were pretty experienced developers who used C++ every day, but =
just
>>>>> never needed to write templates much in their normal code. To validat=
e that
>>>>> this wasn=E2=80=99t just an outlier group, I=E2=80=99ve watched that =
exercise in a number
>>>>> of classes over several years and found a similar result =E2=80=93 th=
e majority of
>>>>> even reasonably experienced C++ programmers asked about the syntax fo=
r how
>>>>> to write a template.
>>>>>
>>>>
>>>> This very much matches my experience- as far as I can tell, the vast
>>>> majority of C++ code is non-template code. But why is that surprising,=
and
>>>> why do you expect concepts to change it?
>>>>
>>>>
>>> That's my experience as well. However, I can also say that concepts is
>>> not what would get me to write more templates, as concepts (as it is
>>> currently proposed) only makes *using* templates easier (by declaring
>>> up-front what the requirements are). It doesn't make implementing a
>>> function easier (by checking each point of use to see if it is a requir=
ed
>>> behavior).
>>>
>>
>> Interesting; my impression was the other way around, that concepts make
>> it easier to write templates, but not really easier to use them. The mai=
n
>> functional advantage that I see with concepts is that they let you contr=
ol
>> the overload set much more easily (and much more readably), and that hel=
ps
>> template authors, not template users. I see your point about declaring t=
he
>> requirements up-front, but decent template libraries already do that in =
the
>> documentation; I'm not sure that formalizing those requirements in code
>> will really help users much.
>>
>
> You assume that users actually read that documentation. Or remember it
> when they read it.
>
> If someone gives you an abstract base class to implement, the requirement=
s
> are listed right there, in the language. You have to derive from that
> class; derive from the wrong one, and you'll get a compiler error
> somewhere. You have to override all pure-virtual methods; type the method
> name wrong, and you get a compiler error somewhere (either due to the cla=
ss
> still being abstract or because you used "override" and there was no base
> class function). And so forth.
>
_Some_ of the requirements are embedded in the code, but not all. Those
methods I'm overriding probably have contracts, and the compiler will not
be able to tell me when I violate them. There's just no helping the
programmers who don't read the documentation, but I think they're a
minority.
>
> If I give a non-moveable type to std::vector<T>, it will give me some kin=
d
> of compiler error. What kind? God only knows, but more likely than not, i=
t
> will be long, obtuse, and generally indecipherable if you've never seen i=
t
> before. This is because the compilation failure happens somewhere in the
> instantiation of std::vector<T> when it tries to actually use your type i=
n
> a way that it can't be used. So the compiler will point to the guts of
> std::vector<T>'s implementation, rather than at your code where the actua=
l
> mistake was made.
>
> If I give a non-moveable type to std::vector<MoveConstructable>, it will
> give me a much cleaner error message. With a semi-decent compiler, it'll
> point you right to the line where you instantiated your std::vector and s=
ay
> "Hey, your type T isn't MoveConstructable, because it doesn't have a move
> constructor." At the very least, I won't get a giant spew of template stu=
ff.
>
> Concepts are great at telling me what I did wrong when I misuse a
> template. Which means I will feel much more confident that, if it compile=
d,
> I'm using the template correctly.
>
I grant you that concepts have the potential to improve template error
messages, but as your example showed, the errors that they catch tend to be
errors that would have been caught anyway by ordinary type checking, so I
don't see how your increased confidence can be justified.
--=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/.
--001a113506b87925820510a7f390
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">=
On Fri, Mar 6, 2015 at 2:23 PM, Nicol Bolas <span dir=3D"ltr"><<a href=
=3D"mailto:jmckesson@gmail.com" target=3D"_blank">jmckesson@gmail.com</a>&g=
t;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0=
.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><br><br=
>On Friday, March 6, 2015 at 4:25:51 PM UTC-5, Geoffrey Romer wrote:<span c=
lass=3D""><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"><div><br=
><div class=3D"gmail_quote">On Fri, Mar 6, 2015 at 12:11 PM, Nicol Bolas <s=
pan dir=3D"ltr"><<a rel=3D"nofollow">jmck...@gmail.com</a>></span> wr=
ote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border=
-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><br><br>On Friday, =
March 6, 2015 at 2:27:23 PM UTC-5, Geoffrey Romer wrote:<span><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #c=
cc solid;padding-left:1ex"><div dir=3D"ltr"><div><br><div class=3D"gmail_qu=
ote">On Fri, Mar 6, 2015 at 10:27 AM, Herb Sutter <span dir=3D"ltr"><<a =
rel=3D"nofollow">hsu...@microsoft.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">
<div link=3D"#0563C1" vlink=3D"#954F72" lang=3D"EN-US">
<div><span>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">></span> To the novice C++ program=
mer, it
<i>isn't</i> "all just programming." Whether something is a t=
emplate <i>matters</i>.<span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
</span><p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:&=
quot;Calibri",sans-serif;color:#1f497d">Why? Only because of where you=
put the definition, and that=E2=80=99s (a) teachable and (b) not new becau=
se the same issue exists already with:<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto f() { =E2=80=A6=
};<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">This is not a template, but must appe=
ar in a header. This is amazingly similar =E2=80=93 and easy to teach as =
=E2=80=9Cif the declaration mentions =E2=80=98auto=E2=80=99 or a concept na=
me, the
compiler needs the definition, either to deduce something or to inline the=
body into the caller.=E2=80=9D Right?<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">Herb<u></u><u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d"><u></u>=C2=A0<u></u></span></p>
<p class=3D"MsoNormal"><span style=3D"font-size:11.0pt;font-family:"Ca=
libri",sans-serif;color:#1f497d">PS =E2=80=93 Since you mention =E2=80=
=9Cnovices=E2=80=9D writing templates, in my experience (and to my surprise=
) I=E2=80=99ve found that not only novices but also intermediate developers=
(like
5-7 year veterans) don=E2=80=99t write templates very much. [I expect this=
to change with concepts, for the good.] I discovered this by chance when I=
had a class exercise that included writing a very simple template, and as =
I walked through the class during the exercise
I was surprised that most of the groups asked about the syntax for writing=
a template =E2=80=93 a dead giveaway that they didn=E2=80=99t write templa=
tes very often, yet these were pretty experienced developers who used C++ e=
very day, but just never needed to write templates
much in their normal code. To validate that this wasn=E2=80=99t just an ou=
tlier group, I=E2=80=99ve watched that exercise in a number of classes over=
several years and found a similar result =E2=80=93 the majority of even re=
asonably experienced C++ programmers asked about the syntax
for how to write a template.</span></p></div></div></blockquote><div><br><=
/div><div>This very much matches my experience- as far as I can tell, the v=
ast majority of C++ code is non-template code. But why is that surprising, =
and why do you expect concepts to change it?<br></div></div><br></div></div=
></blockquote></span><div><br>That's my experience as well. However, I =
can also say that concepts is not what would get me to write more templates=
, as concepts (as it is currently proposed) only makes <i>using</i> templat=
es easier (by declaring up-front what the requirements are). It doesn't=
make implementing a function easier (by checking each point of use to see =
if it is a required behavior).<br></div></div></blockquote><div><br></div><=
div>Interesting; my impression was the other way around, that concepts make=
it easier to write templates, but not really easier to use them. The main =
functional advantage that I see with concepts is that they let you control =
the overload set much more easily (and much more readably), and that helps =
template authors, not template users. I see your point about declaring the =
requirements up-front, but decent template libraries already do that in the=
documentation; I'm not sure that formalizing those requirements in cod=
e will really help users much.</div></div></div></div></blockquote></span><=
div><br>You assume that users actually read that documentation. Or remember=
it when they read it.<br><br>If someone gives you an abstract base class t=
o implement, the requirements are listed right there, in the language. You =
have to derive from that class; derive from the wrong one, and you'll g=
et a compiler error somewhere. You have to override all pure-virtual method=
s; type the method name wrong, and you get a compiler error somewhere (eith=
er due to the class still being abstract or because you used "override=
" and there was no base class function). And so forth.<br></div></div>=
</blockquote><div><br></div><div>_Some_ of the requirements are embedded in=
the code, but not all. Those methods I'm overriding probably have cont=
racts, and the compiler will not be able to tell me when I violate them. Th=
ere's just no helping the programmers who don't read the documentat=
ion, but I think they're a minority.</div><div>=C2=A0</div><blockquote =
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid=
;padding-left:1ex"><div dir=3D"ltr"><div><br>If I give a non-moveable type =
to std::vector<T>, it will give me some kind of compiler error. What =
kind? God only knows, but more likely than not, it will be long, obtuse, an=
d generally indecipherable if you've never seen it before. This is beca=
use the compilation failure happens somewhere in the instantiation of std::=
vector<T> when it tries to actually use your type in a way that it ca=
n't be used. So the compiler will point to the guts of std::vector<T=
>'s implementation, rather than at your code where the actual mistak=
e was made.<br><br>If I give a non-moveable type to std::vector<MoveCons=
tructable>, it will give me a much cleaner error message. With a semi-de=
cent compiler, it'll point you right to the line where you instantiated=
your std::vector and say "Hey, your type T isn't MoveConstructabl=
e, because it doesn't have a move constructor." At the very least,=
I won't get a giant spew of template stuff.<br><br>Concepts are great =
at telling me what I did wrong when I misuse a template. Which means I will=
feel much more confident that, if it compiled, I'm using the template =
correctly.<br></div></div></blockquote><div><br></div><div>I grant you that=
concepts have the potential to improve template error messages, but as you=
r example showed, the errors that they catch tend to be errors that would h=
ave been caught anyway by ordinary type checking, so I don't see how yo=
ur increased confidence can be justified.</div></div><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 />
--001a113506b87925820510a7f390--
.