Topic: Request for interest: easier metaprogramming, bye bye
Author: =?UTF-8?Q?Germ=C3=A1n_Diago?= <germandiago@gmail.com>
Date: Wed, 21 Oct 2015 00:38:06 -0700 (PDT)
Raw View
------=_Part_5720_184495556.1445413086975
Content-Type: multipart/alternative;
boundary="----=_Part_5721_1193852577.1445413086975"
------=_Part_5721_1193852577.1445413086975
Content-Type: text/plain; charset=UTF-8
Hello everyone,
Every day I look at the D language metaprogramming facilities, I get more
convinced that
there are things missing in C++ that should make it in. Especially some
kind of string
mixin would be beneficial to get rid of some other preprocessor uses.
I would like to know if there would be interest for the following proposals:
In particular, I see that:
1. Not allowing string literals in templates is very painful: for a natural
syntax we have
to rely on creating a variable and passing a reference to the template
argument and
similar things. I saw several proposals, there will be some for C++17.
2.- You cannot do what you can do with string mixin in C++ without macros,
and we should get rid of macros, the sooner, the better, except for very
niche uses.
I have seen a few good uses of this technique.
For example:
a. Named tuples.
using Employee = tuple<string, "name", int, "age">;
Employee e;
e.name = ...;
e.age = ...;
b. DSLs, for example databases with injected variables from the program in
the query.
auto employees...;
auto query = make_query<"select * from employees where age > 32">(
For example, in this query you could directly relate the employees in that
string to the variable
employees in the program without the need of explicit mapping.
c. Named regular expressions
std::string surname = "Smith";
regex_match(ctregex<"A.*" + "{surname}">, input);
d. my_printf with named string interpolation
auto a_friend = "CppUser";
my_printf("Hello {a_friend}");
3. Universal template parameter (like alias in D): a template parameter
that can be either a type
or a value:
This, combined with mixins and strings, can make for terse lambdas, for
example, as you can
see in D standard library:
filter!"a < 5"(...);
4. Static if. (I saw constexpr_if in Pre-Kona). Seems the proposal does not
allow for out of block
evaluation, so the problem here would be that we cannot use it insted of
#if/#ifdef. I think those
cases should be covered with some non-preprocessor alternative.
I think the examples shown are quite motivational and they are examples of
things that I cannot
easily achieve with current C++. Things that are useful in practice, in my
humble opinion.
Feedback is welcome for opinions in all these 4 features.
Regards
--
---
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_5721_1193852577.1445413086975
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hello everyone,<br><br>Every day I look at the D language =
metaprogramming facilities, I get more convinced that<br>there are things m=
issing in C++ that should make it in. Especially some kind of string<br>mix=
in would be beneficial to get rid of some other preprocessor uses.<br><br><=
br>I would like to know if there would be interest for the following propos=
als:<br><br>In particular, I see that:<br><br>1. Not allowing string litera=
ls in templates is very painful: for a natural syntax we have<br>to rely on=
creating a variable and passing a reference to the template argument and<b=
r>similar things. I saw several proposals, there will be some for C++17.<br=
><br><br>2.- You cannot do what you can do with string mixin in C++ without=
macros,<br>and we should get rid of macros, the sooner, the better, except=
for very niche uses.<br>=C2=A0I have seen a few good uses of this techniqu=
e. <br><br>For example:<br><br>a. Named tuples. <br><br>using Employee =3D =
tuple<string, "name", int, "age">;<br><br>Employe=
e e;<br>e.name =3D ...;<br>e.age =3D ...;<br><br>b.=C2=A0 DSLs, for example=
databases with injected variables from the program in the query.<br><br>au=
to employees...;<br><br>auto query =3D make_query<"select * from em=
ployees where age > 32">(<br><br>For example, in this query you =
could directly relate the employees in that string to the variable<br>emplo=
yees in the program without the need of explicit mapping.<br><br>c. Named r=
egular expressions<br><br>std::string surname =3D "Smith"; <br>re=
gex_match(ctregex<"A.*" + "{surname}">, input);<b=
r><br>d. my_printf with named string interpolation<br><br>auto a_friend =3D=
"CppUser";<br>my_printf("Hello {a_friend}");<br><br>3.=
Universal template parameter (like alias in D): a template parameter that =
can be either a type<br>or a value:<br><br>This, combined with mixins and s=
trings, can make for terse lambdas, for example, as you can<br>see in D sta=
ndard library:<br><br>filter!"a < 5"(...);<br><br>4. Static if=
.. (I saw constexpr_if in Pre-Kona). Seems the proposal does not allow for o=
ut of block<br>evaluation, so the problem here would be that we cannot use =
it insted of #if/#ifdef. I think those<br>cases should be covered with some=
non-preprocessor alternative.<br><br><br>I think the examples shown are qu=
ite motivational and they are examples of things that I cannot<br>easily ac=
hieve with current C++. Things that are useful in practice, in my humble op=
inion.<br><br>Feedback is welcome for opinions in all these 4 features.<br>=
<br>Regards<br><br><br><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 <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 />
------=_Part_5721_1193852577.1445413086975--
------=_Part_5720_184495556.1445413086975--
.