Topic: concepts as constexpr variable templates
Author: inkwizytoryankes@gmail.com
Date: Sat, 6 Jul 2013 08:39:32 -0700 (PDT)
Raw View
------=_Part_19_4527418.1373125172507
Content-Type: text/plain; charset=ISO-8859-1
In latest proposition (n3701) concepts are defined as template constexpr
function that take no arguments and always return bool.
template<typename T>
concept bool Foo()
{
return Bar<T>() && requires (T a) { {*a} -> int; };
}
template<typename T>
requires Foo<T>()
class F { };
I think better is use syntax from variable templates that will have less
"noise" than equal constexpr function.
template<typename T>
concept bool Foo = Bar<T> && requires (T a) { {*a} -> int; };
template<typename T>
requires Foo<T>
class F { };
Grain is that we dont need type `()` everywhere that dong give us anything
(concepts cant have any arguments) .
Only problem I see right now is preventing overloading of concept template
template<typename T>
concept bool Foo() { return true; }
template<typename T, typename T2>
concept bool Foo() { return true; }
template<Foo F>
class Bar { };
template<typename F1, typename F2> requires Foo<F1, F2>
class Bar2 { };
But it can be avoided by using default template parameters or variadic
templates.
Another thing I think could be change is place where `requires` apper in
function/class definition
template<typename T>
//requires Foo<T> <- removed
class A : public B requires Foo<T> // <- added
{
void func() requires Bar<T>; //from n3701
template<typename N>
//requires Caa<N, T> <- removed
void func(N n) requires Caa<N, T>; // <- added
};
this will be more consist with member function.
In similar way C# handle keyword `where`:
//C#
class Foo<T> : Bar where T : ISomething { }
void foo<T>(int i) where T : new() { }
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_19_4527418.1373125172507
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
In latest proposition (n3701) concepts are defined as template constexpr fu=
nction that take no arguments and always return bool.<br><div class=3D"pret=
typrint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(1=
87, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-wor=
d;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">template</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">></span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">concept</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">bool</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Foo</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">return</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
06;" class=3D"styled-by-prettify">Bar</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">>()</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
amp;&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
requires </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T a</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{*</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">a</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">-></span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
template</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&l=
t;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">typename=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">></span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br> </span=
><span style=3D"color: rgb(0, 0, 255);"><span style=3D"color: #000;" class=
=3D"styled-by-prettify">requires </span></span><span style=3D"color: #606;"=
class=3D"styled-by-prettify">Foo</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">>()</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">c=
lass</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> F </s=
pan><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: #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br><br></span></div></code></div><br>I=
think better is use syntax from variable templates that will have less "no=
ise" than equal constexpr function.<br><div class=3D"prettyprint" style=3D"=
background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); bor=
der-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D=
"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: rgb(0, 0,=
0);"><span style=3D"color: rgb(0, 0, 255);"><span class=3D"styled-by-prett=
ify">template</span></span><span class=3D"styled-by-prettify"><</span><s=
pan style=3D"color: rgb(0, 0, 255);"><span class=3D"styled-by-prettify">typ=
ename</span></span><span class=3D"styled-by-prettify"><span style=3D"color:=
rgb(0, 0, 255);"> </span>T</span><span class=3D"styled-by-prettify">></=
span><span class=3D"styled-by-prettify"></span><br></span><code class=3D"pr=
ettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify"><span =
style=3D"color: rgb(0, 0, 0);"><span style=3D"color: rgb(0, 0, 255);">conce=
pt bool</span> Foo =3D Bar<T> && <span style=3D"color: rgb(0,=
0, 255);">requires </span>(T a) { {*a} -> <span style=3D"color: rgb(0, =
0, 255);">int</span>; };<br><br><span style=3D"color: rgb(0, 0, 255);">temp=
late</span><<span style=3D"color: rgb(0, 0, 255);">typename </span>T>=
<br> <span style=3D"color: rgb(0, 0, 255);">requires</spa=
n> Foo<T><br><span style=3D"color: rgb(0, 0, 255);">class </span>F { =
};<br></span><br></span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify"></=
span></code></div></code></div><br>Grain is that we dont need type `()` eve=
rywhere that dong give us anything (concepts cant have any arguments) .<br>=
<br>Only problem I see right now is preventing overloading of concept templ=
ate<br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, =
250); border-color: rgb(187, 187, 187); border-style: solid; border-width: =
1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><span style=3D"color: rgb(0, 0, 0);"><span class=3D"styled-by-p=
rettify"><span style=3D"color: rgb(0, 0, 255);">template</span><<span st=
yle=3D"color: rgb(0, 0, 255);">typename </span>T><br><span style=3D"colo=
r: rgb(0, 0, 255);">concept bool</span> Foo() { <span style=3D"color: rgb(0=
, 0, 255);">return true</span>; }<br><br><span style=3D"color: rgb(0, 0, 25=
5);">template</span><</span></span><span style=3D"color: rgb(0, 0, 0);">=
<span class=3D"styled-by-prettify"><code class=3D"prettyprint"><span style=
=3D"color: rgb(0, 0, 0);"><span class=3D"styled-by-prettify"><span style=3D=
"color: rgb(0, 0, 255);">typename </span>T</span></span></code></span></spa=
n><span style=3D"color: rgb(0, 0, 0);"><span class=3D"styled-by-prettify"><=
code class=3D"prettyprint"><span style=3D"color: rgb(0, 0, 0);"><span class=
=3D"styled-by-prettify"><code class=3D"prettyprint"><span style=3D"color: r=
gb(0, 0, 0);"><span class=3D"styled-by-prettify"><span style=3D"color: rgb(=
0, 0, 255);">, typename </span>T</span></span></code></span></span></code>2=
><br><span style=3D"color: rgb(0, 0, 255);">concept bool</span> Foo() { =
<span style=3D"color: rgb(0, 0, 255);">return true</span>; }</span><span cl=
ass=3D"styled-by-prettify"></span><br></span><code class=3D"prettyprint"><s=
pan style=3D"color: rgb(0, 0, 0);"><br><span style=3D"color: rgb(0, 0, 255)=
;">template</span><Foo F><span style=3D"color: rgb(153, 153, 153);"><=
/span><br><span style=3D"color: rgb(0, 0, 255);">class</span> Bar { };</spa=
n></code><code class=3D"prettyprint"><span style=3D"color: rgb(0, 0, 0);"><=
br><br><span style=3D"color: rgb(0, 0, 255);">template</span><</span></c=
ode><code class=3D"prettyprint"><span style=3D"color: rgb(0, 0, 0);"><code =
class=3D"prettyprint"><span style=3D"color: rgb(0, 0, 0);"><span class=3D"s=
tyled-by-prettify"><code class=3D"prettyprint"><span style=3D"color: rgb(0,=
0, 0);"><span class=3D"styled-by-prettify"><span style=3D"color: rgb(0, 0,=
255);">typename </span></span></span></code></span></span></code>F1, </spa=
n></code><code class=3D"prettyprint"><span style=3D"color: rgb(0, 0, 0);"><=
code class=3D"prettyprint"><span style=3D"color: rgb(0, 0, 0);"><span class=
=3D"styled-by-prettify"><code class=3D"prettyprint"><span style=3D"color: r=
gb(0, 0, 0);"><span class=3D"styled-by-prettify"><span style=3D"color: rgb(=
0, 0, 255);">typename </span></span></span></code></span></span></code></sp=
an></code><code class=3D"prettyprint"><span style=3D"color: rgb(0, 0, 0);">=
<code class=3D"prettyprint"><span style=3D"color: rgb(0, 0, 0);"><span clas=
s=3D"styled-by-prettify"><code class=3D"prettyprint"><span style=3D"color: =
rgb(0, 0, 0);"><span class=3D"styled-by-prettify"><span style=3D"color: rgb=
(0, 0, 255);"><code class=3D"prettyprint"><code class=3D"prettyprint"><span=
style=3D"color: rgb(0, 0, 0);">F2</span></code></code></span></span></span=
></code></span></span></code>><span style=3D"color: rgb(153, 153, 153);"=
></span> </span></code><code class=3D"prettyprint"><span style=3D"color: rg=
b(0, 0, 0);"><code class=3D"prettyprint"><span style=3D"color: rgb(0, 0, 0)=
;"><span class=3D"styled-by-prettify"><span style=3D"color: rgb(0, 0, 255);=
">requires </span></span></span></code></span></code><code class=3D"prettyp=
rint"><span style=3D"color: rgb(0, 0, 0);"><code class=3D"prettyprint"><spa=
n style=3D"color: rgb(0, 0, 0);"><span class=3D"styled-by-prettify"><span s=
tyle=3D"color: rgb(0, 0, 255);"><code class=3D"prettyprint"><span style=3D"=
color: rgb(0, 0, 0);"><span class=3D"styled-by-prettify">Foo<F1, F2><=
/span></span></code><br> </span></span></span></code><span style=3D"color: =
rgb(0, 0, 255);">class</span> Bar2 { };</span></code></div></code></div>But=
it can be avoided by using default template parameters or variadic templat=
es.<br><br><br>Another thing I think could be change is place where `requir=
es` apper in function/class definition<br><br><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: rg=
b(0, 0, 255);"><span class=3D"styled-by-prettify"></span></span><span style=
=3D"color: rgb(0, 0, 0);"><span class=3D"styled-by-prettify"><span style=3D=
"color: rgb(0, 0, 255);">template</span><<span style=3D"color: rgb(0, 0,=
255);">typename </span>T><br><span style=3D"color: rgb(153, 153, 153);"=
>//</span></span><span class=3D"styled-by-prettify"><span style=3D"color: r=
gb(153, 153, 153);"><code class=3D"prettyprint"><span class=3D"styled-by-pr=
ettify">requires Foo<T></span></code> </span><span style=
=3D"color: rgb(255, 0, 0);"><span style=3D"color: rgb(153, 153, 153);"> </s=
pan><- removed</span><br><span style=3D"color: rgb(0, 0, 255);">class </=
span>A : <span style=3D"color: rgb(0, 0, 255);">public </span>B <span style=
=3D"color: rgb(0, 0, 255);">requires </span>Foo<T></span></span><span=
style=3D"color: rgb(0, 0, 0);"><span class=3D"styled-by-prettify"><code cl=
ass=3D"prettyprint"><span style=3D"color: #660;" class=3D"styled-by-prettif=
y"><span style=3D"color: rgb(0, 0, 0);"> // <span style=3D"color: rgb(0, 25=
5, 0);"><- added</span></span></span></code><br>{<br> =
<span style=3D"color: rgb(0, 0, 255);">void </span>func() <span style=3D"co=
lor: rgb(0, 0, 255);">requires </span>Bar<T>; //from </span></span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify"><span style=3D"colo=
r: rgb(0, 0, 0);">n3701<br><br> <span style=3D"color: rgb=
(0, 0, 255);">template</span><<span style=3D"color: rgb(0, 0, 255);">typ=
ename </span>N><br> <span style=3D"color: rgb(153, 153=
, 153);">//requires Caa<N, T></span> <span style=3D"color=
: rgb(255, 0, 0);"><- removed</span><br> <span style=
=3D"color: rgb(0, 0, 255);">void </span>func(N n) <span style=3D"color: rgb=
(0, 0, 255);">requires </span>Caa<N, T>; // <span style=3D"color: rgb=
(0, 255, 0);"><- added</span><br>};</span><br></span></div></code></div>=
<br>this will be more consist with member function.<br>In similar way C# ha=
ndle keyword `where`:<br><br><div class=3D"prettyprint" style=3D"background=
-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style:=
solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettypri=
nt"><div class=3D"subprettyprint"><span style=3D"color: #606;" class=3D"sty=
led-by-prettify">//C#<br>class Foo<T> : Bar where T : ISomething { }<=
br>void foo<T>(int i) where T : new() { }<br></span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify"></span></div></code></div><br><br>=
<br><br><br><br><br><br><br>
<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
<br />
<br />
------=_Part_19_4527418.1373125172507--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Sat, 06 Jul 2013 10:02:38 -0700
Raw View
--nextPart2875725.HSP5WoynI9
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="iso-8859-1"
On s=E1bado, 6 de julho de 2013 08.39.32, inkwizytoryankes@gmail.com wr=
ote:
> I think better is use syntax from variable templates that will have l=
ess=20
> "noise" than equal constexpr function.
> template<typename T>
> concept bool Foo =3D Bar<T> && requires (T a) { {*a} -> int; };
>=20
> template<typename T>
> requires Foo<T>
> class F { };
>=20
>=20
> Grain is that we dont need type `()` everywhere that dong give us any=
thing=20
> (concepts cant have any arguments) .
Making it a function allows you to have local typedefs, without polluti=
ng the=20
enclosing namespace.
template<typename T>
concept bool Foo()
{
typedef std::iterator<T> Iterator;
return Bar<Iterator>() && requires (T a) { {*a} -> int; };
}
--=20
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--nextPart2875725.HSP5WoynI9
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
iD8DBQBR2E2uM/XwBW70U1gRAv3+AKCcp07VPqZljLJLOpUg+PcXyleOCACeM96m
vWy5dPtrtZIpZ9PMsVU8hGI=
=IAOp
-----END PGP SIGNATURE-----
--nextPart2875725.HSP5WoynI9--
.
Author: inkwizytoryankes@gmail.com
Date: Sat, 6 Jul 2013 10:59:44 -0700 (PDT)
Raw View
------=_Part_3216_25448788.1373133584818
Content-Type: text/plain; charset=ISO-8859-1
On Saturday, July 6, 2013 7:02:38 PM UTC+2, Thiago Macieira wrote:
> Making it a function allows you to have local typedefs, without polluting
> the
> enclosing namespace.
>
> template<typename T>
> concept bool Foo()
> {
> typedef std::iterator<T> Iterator;
> return Bar<Iterator>() && requires (T a) { {*a} -> int; };
> }
>
Right, in my version that will be problematic but in templates that us that
concept this typedef will be used too.
Especially when is complex definition. This will require another typedef in
enclosing namespace.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_3216_25448788.1373133584818
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><br>On Saturday, July 6, 2013 7:02:38 PM UTC+2, Thiago Macieira wrote:<=
br><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;=
border-left: 1px #ccc solid;padding-left: 1ex;">Making it a function allows=
you to have local typedefs, without polluting the=20
<br>enclosing namespace.
<br>
<br>template<typename T>
<br>concept bool Foo()
<br>{
<br> typedef std::iterator<T> Iterator;
<br> return Bar<Iterator>() && requires (T a) { =
{*a} -> int; };
<br>}
<br></blockquote><div>Right, in my version that will be problematic but in =
templates that us that concept this typedef will be used too.<br>Especially=
when is complex definition. This will require another typedef in enclosing=
namespace.<br></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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />
<br />
<br />
------=_Part_3216_25448788.1373133584818--
.