Topic: Concepts shorthand & short-form notations: make an
Author: TONGARI J <tongari95@gmail.com>
Date: Thu, 23 Feb 2017 22:54:20 -0800 (PST)
Raw View
------=_Part_216_829104249.1487919260752
Content-Type: multipart/alternative;
boundary="----=_Part_217_222921118.1487919260753"
------=_Part_217_222921118.1487919260753
Content-Type: text/plain; charset=UTF-8
A constrained template is written in this way (verbose):
template<typename T>
requires ConceptName<T>
void algo(T const&);
In p0557r0, it mentions shorthand notation:
template<ConceptName T>
void algo(T const&);
And short-form notation:
void algo(ConceptName const&);
While C++17 introduces template <auto v>, so what does template<Integer I>
mean? should `I` be an auto-deduced template non-type arg? or should it be
a template type arg constrained by Integer? Either way, it's confusing.
I think we'd better separate the domains of types & values:
A shorthand notation becomes:
template<typename:ConceptName T>
void algo(T const&);
Note that typename & class is interchangeable here.
A short-form notation becomes:
void algo(auto:ConceptName const&);
Note that in this way, it's obvious that if 2 more args have the same
Concept, they may deduce to different types, just as non-constrained auto.
void algo(auto:ConceptName const& a, auto:ConceptName const& b);
Although it's little more verbose that the original ones, I think it adds
great clarity to the code while still keeps the brevity.
Has similar idea been discussed before?
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/88843922-dd0d-4b59-af78-d1dccbdc7a7b%40isocpp.org.
------=_Part_217_222921118.1487919260753
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>A constrained template is written in this way (verbos=
e):</div><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250=
, 250); border-color: rgb(187, 187, 187); border-style: solid; border-width=
: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"su=
bprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">tem=
plate</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><<=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">></span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 requires =
</span><span style=3D"color: #606;" class=3D"styled-by-prettify">ConceptNam=
e</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">T</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> algo</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">T </span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">const</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&);</span></div></code></div><br><div><div>In=C2=A0p0557r0, it =
mentions=C2=A0shorthand=C2=A0notation:</div></div><div><div class=3D"pretty=
print" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187=
, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-word;=
"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"=
color: #008;" class=3D"styled-by-prettify">template</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #=
606;" class=3D"styled-by-prettify">ConceptName</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> algo</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&);</span><=
/div></code></div><span class=3D"styled-by-prettify" style=3D"font-family: =
monospace; background-color: rgb(250, 250, 250); color: rgb(102, 102, 0);">=
<div><span class=3D"styled-by-prettify" style=3D"font-family: monospace; ba=
ckground-color: rgb(250, 250, 250); color: rgb(102, 102, 0);"><br></span></=
div></span>And short-form notation:</div><div><div class=3D"prettyprint" st=
yle=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 18=
7); border-style: solid; border-width: 1px; word-wrap: break-word;"><code c=
lass=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> algo</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">ConceptName</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">const</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">&);</span></div></code></div><span class=3D"styled-by-prettify" style=
=3D"font-family: monospace; background-color: rgb(250, 250, 250); color: rg=
b(102, 102, 0);"><br></span>While C++17 introduces=C2=A0<span class=3D"styl=
ed-by-prettify" style=3D"color: rgb(0, 0, 136);">template</span><span class=
=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);">=C2=A0</span><span c=
lass=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);"><</span><=
span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136);">auto</sp=
an><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);">=C2=A0=
v</span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0)=
;">></span>, so what does=C2=A0<span class=3D"styled-by-prettify" style=
=3D"font-family: monospace; background-color: rgb(250, 250, 250); color: rg=
b(0, 0, 136);">template</span><span class=3D"styled-by-prettify" style=3D"f=
ont-family: monospace; background-color: rgb(250, 250, 250); color: rgb(102=
, 102, 0);"><</span><span class=3D"styled-by-prettify" style=3D"font-fam=
ily: monospace; background-color: rgb(250, 250, 250);"><font color=3D"#6600=
66">Integer I</font></span><span class=3D"styled-by-prettify" style=3D"font=
-family: monospace; background-color: rgb(250, 250, 250); color: rgb(102, 1=
02, 0);">></span> mean? should `I` be an auto-deduced template non-type =
arg? or should it be a template type arg constrained by Integer? Either way=
, it's confusing.</div><div><br></div><div>I think we'd better sepa=
rate the domains of types & values:</div><div><br></div><div>A shorthan=
d=C2=A0notation becomes:</div><div class=3D"prettyprint" style=3D"backgroun=
d-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style=
: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettypr=
int"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">template</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">typename</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">:</span><span style=3D"color: #606;" class=3D"styled-by-prettify">C=
onceptName</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">></sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> algo</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">T </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">const</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&);</span></div></code></div>Note that=C2=A0<sp=
an style=3D"color: rgb(0, 0, 136); font-family: monospace; background-color=
: rgb(250, 250, 250);">typename=C2=A0</span>&=C2=A0<span style=3D"color=
: rgb(0, 0, 136);">class=C2=A0</span>is interchangeable here.<div><span cla=
ss=3D"styled-by-prettify" style=3D"font-family: monospace; background-color=
: rgb(250, 250, 250); color: rgb(102, 102, 0);"><br></span></div><div>A sho=
rt-form notation becomes:</div><div><div class=3D"prettyprint" style=3D"bac=
kground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border=
-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pr=
ettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> algo</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">auto</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:<=
/span><span style=3D"color: #606;" class=3D"styled-by-prettify">ConceptName=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&);</span></div></co=
de></div></div><div><br></div><div>Note that in this way, it's obvious =
that if 2 more args have the same Concept, they may deduce to different typ=
es, just as non-constrained auto.</div><div><div class=3D"prettyprint" styl=
e=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187)=
; border-style: solid; border-width: 1px; word-wrap: break-word;"><code cla=
ss=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008=
;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> algo</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">auto</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">:</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Con=
ceptName</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> a</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">auto</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">:</span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">ConceptName</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">const</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> b<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span></=
div></code></div><span style=3D"background-color: rgb(250, 250, 250); color=
: rgb(102, 102, 0); font-family: monospace;"><br></span></div>Although it&#=
39;s little more verbose that the original ones, I think it adds great clar=
ity to the code while still keeps the brevity.<br><div>Has similar idea bee=
n discussed before?</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/88843922-dd0d-4b59-af78-d1dccbdc7a7b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/88843922-dd0d-4b59-af78-d1dccbdc7a7b=
%40isocpp.org</a>.<br />
------=_Part_217_222921118.1487919260753--
------=_Part_216_829104249.1487919260752--
.