Topic: Augment the Preprocessor to Get Rid of Mores Uses


Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Tue, 13 Dec 2016 17:36:11 -0800 (PST)
Raw View
------=_Part_1584_1277808112.1481679371308
Content-Type: multipart/alternative;
 boundary="----=_Part_1585_313722150.1481679371309"

------=_Part_1585_313722150.1481679371309
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Tuesday, December 13, 2016 at 7:36:06 AM UTC-8, Ricardo Andrade wrote:
>
>
> *The Macro Listing Operation*
>
> This is an operation which lists the declared macros. [...]
> it is proposed to have a function-like internal macro tentatively named:=
=20
> __DEFINED_MACROS__(filter)
>
> Being "filter" a string literal (more below).
> The returned value is the following:
> - If the filter matches anything, the result is the comma-separated macro=
=20
> names.
> - If no matches are found, the result is nothing.
> [...]
> For example, using the following snippet (extracted from OpenLDAP ldap.h)=
:
>
> #define LDAP_DEBUG_TRACE 0x001
> #define LDAP_DEBUG_PACKETS 0x002
> #define LDAP_DEBUG_ARGS  0x004
>
> The call below:
> __DEFINED_MACROS__("LDAP_DEBUG_*")
>
> Would have the result of:
>
> LDAP_DEBUG_TRACE, LDAP_DEBUG_PACKETS, LDAP_DEBUG_ARGS
>
> Which in turn could be input for (non working, just illustrative):
>
> #define FOR_EACH(function, ...) // out of the scope of this proposal
> #define DECLARE_ENUM(macro) e#macro =3D macro,
> // Redeclare LDAP debug constants as a strong-typed enum.
> enum class LdapDebug {
> FOR_EACH(DECLARE_ENUM, __DEFINED_MACROS__("LDAP_DEBUG_*"));
> }; // aware of the trailing comma, please ignore it
>
> Now, LdapDebug names and values could be used in C++ and also available=
=20
> to reflection.
>

It sounds like you're proposing that working programmers should write code=
=20
such as

// approach (P)
#include "ldap.h"
#define FOR_EACH(function, ...) // yikes
#define DECLARE_ENUM(x) e##x =3D x,
enum class LdapDebug {
FOR_EACH(DECLARE_ENUM, __DEFINED_MACROS__("LDAP_DEBUG_*"));
};

where the // yikes stands for a lot of preprocessor metaprogramming that=20
even I don't want to tackle, although I'm aware that libraries such as 8pp=
=20
exist for the purpose.
I don't understand why any programmer would want to go to all the above=20
effort instead of either

// approach (A)
enum class LdapDebug {
    eLDAP_DEBUG_TRACE =3D 1,
    eLDAP_DEBUG_PACKETS =3D 2,
    eLDAP_DEBUG_ARGS =3D 4,
};

// or approach (B)
#include "ldap.h"
enum class LdapDebug {
    eLDAP_DEBUG_TRACE =3D LDAP_DEBUG_TRACE,
    eLDAP_DEBUG_PACKETS =3D LDAP_DEBUG_PACKETS,
    eLDAP_DEBUG_ARGS =3D LDAP_DEBUG_ARGS,
};

or approach (C), which would be to submit a pull request upstream to=20
"ldap.h".

Stretch this ideas of this proposal a little bit and you can vision=20
> definitions being redeclared this way and used in C++ instead of the lega=
cy=20
> macros which in turn could get deprecated over time (of course, if C=20
> support is to be dropped). The author of this proposal can see derivation=
s=20
> of such work aiding with a better support modules in legacy environments=
=20
> too.
>

I don't understand how encouraging macro metaprogramming would in any way=
=20
lead to the "deprecation" of "legacy macros". If I understand correctly,=20
you're asking for the legacy macro system to be *strengthened* to the point=
=20
where working programmers are using it to do metaprogramming even in C++.=
=20
The general party line in C++ today is that working programmers should not=
=20
be using preprocessor macros for just about anything, because we have=20
semantically safer versions of the same toolkit that are not based on=20
textual substitution: enums, inline functions, pass-by-reference,...
=20

> If such functionality can already be achieved using already available=20
> techniques, I'd love to hear more.
>

I'd point you to approaches A, B, and C above.

=E2=80=93Arthur

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/8ca43f3a-344d-4844-af5e-04898173e11f%40isocpp.or=
g.

------=_Part_1585_313722150.1481679371309
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tuesday, December 13, 2016 at 7:36:06 AM UTC-8, Ricardo=
 Andrade wrote:<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><div><b>The Macro Listing Operation</b><br></div><div><br>=
</div><div>This is an operation which lists the declared macros. [...]</div=
><div>it is proposed to have a function-like internal macro tentatively nam=
ed: __DEFINED_MACROS__(filter)</div><div><br></div><div>Being &quot;filter&=
quot; a string literal (more below).<br></div><div><div>The returned value =
is the following:</div><div>- If the filter matches anything, the result is=
 the comma-separated macro names.</div><div>- If no matches are found, the =
result is nothing.</div></div><div>[...]</div><div>For example, using the f=
ollowing snippet (extracted from OpenLDAP ldap.h):</div><div><pre style=3D"=
color:rgb(0,0,0);word-wrap:break-word;white-space:pre-wrap">#define LDAP_DE=
BUG_TRACE 0x001
#define LDAP_DEBUG_PACKETS 0x002
#define LDAP_DEBUG_ARGS  0x004</pre></div><div>The call below:</div><div>__=
DEFINED_MACROS__(&quot;LDAP_<wbr>DEBUG_*&quot;)</div><div><br></div><div>Wo=
uld have the result of:</div><div><pre style=3D"color:rgb(0,0,0);word-wrap:=
break-word;white-space:pre-wrap">LDAP_DEBUG_TRACE, LDAP_DEBUG_PACKETS, LDAP=
_DEBUG_ARGS</pre></div><div>Which in turn could be input for (non working, =
just illustrative):</div><div><br></div><div><font face=3D"monospace, monos=
pace">#define FOR_EACH(function, ...) // out of the scope of this proposal<=
/font></div><div><font face=3D"monospace, monospace">#define DECLARE_ENUM(m=
acro) e#macro =3D macro,</font></div><div><font face=3D"monospace, monospac=
e">// Redeclare LDAP debug constants as a strong-typed enum.</font></div><d=
iv><font face=3D"monospace, monospace">enum class LdapDebug {</font></div><=
div><font face=3D"monospace, monospace">FOR_EACH(DECLARE_ENUM,=C2=A0__<wbr>=
DEFINED_MACROS__(&quot;LDAP_DEBUG_*<wbr>&quot;));</font></div><div><font fa=
ce=3D"monospace, monospace">}; // aware of the trailing comma, please ignor=
e it</font></div><div><br></div><div>Now, <font face=3D"monospace, monospac=
e">LdapDebug </font>names and values could be used in C++ and also availabl=
e to reflection.</div></div></blockquote><div><br></div><div>It sounds like=
 you&#39;re proposing that working programmers should write code such as</d=
iv><div><br></div><div class=3D"prettyprint" style=3D"background-color: rgb=
(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-wor=
d;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #800;" class=3D"styled-by-prettify">// approach (P)</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">#include</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #080;" class=3D"styled-by-prettify">&quot;ldap.h&quot;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #800;" class=3D"styled-by-prettify">#define</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> FOR_EACH</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">function</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">...)</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">// yike=
s</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n><span style=3D"color: #800;" class=3D"styled-by-prettify">#define</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> DECLARE_ENUM</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">x</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> e</span><span style=3D"color: #800;" clas=
s=3D"styled-by-prettify">##x =3D x,</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">enum</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #606;" class=3D"styled-by-prettify">LdapDebug<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>FOR_EACH</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">DECLARE_ENUM</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> __DEFINED_MACROS__</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #08=
0;" class=3D"styled-by-prettify">&quot;LDAP_DEBUG_*&quot;</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">));</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">};</span></div></code></div><div><div><fo=
nt face=3D"monospace, monospace"><br></font></div></div><div>where the <fon=
t face=3D"courier new, monospace">// yikes</font>=C2=A0stands for a lot of =
preprocessor metaprogramming that even I don&#39;t want to tackle, although=
 I&#39;m aware that libraries such as 8pp exist for the purpose.</div><div>=
I don&#39;t understand why any programmer would want to go to all the above=
 effort instead of either<br></div><div><br></div><div class=3D"prettyprint=
" style=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187,=
 187, 187); word-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styled-by-prettif=
y">// approach (A)</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">enum</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">class</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">LdapDebug</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>=C2=A0 =C2=A0 eLDAP_DEBUG_TRACE </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #066;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br>=C2=A0 =C2=A0 eLDAP_DEBUG_PACKETS </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #06=
6;" class=3D"styled-by-prettify">2</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 eLDAP_DEBUG_ARGS </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">4</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><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: #800;" class=3D"styled-by-prettify">// or appr=
oach (B)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span><span style=3D"color: #800;" class=3D"styled-by-prettify">#include=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #080;" class=3D"styled-by-prettify">&quot;ldap.h&quot;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">enum</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">class</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">LdapDebug</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>=C2=A0 =C2=A0 eLDAP_DEBUG_TRACE </span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> LDAP_DEBUG_TRACE</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 eLDAP_DEBUG_PACKETS </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> LDAP_DEBUG_PACKETS</span><=
span 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 eLDAP_DEB=
UG_ARGS </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> LDAP_D=
EBUG_ARGS</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: #660;" class=3D"styled-by-prettify">};</span></div><=
/code></div><div><br></div><div>or approach (C), which would be to submit a=
 pull request upstream to &quot;ldap.h&quot;.</div><div><br></div><blockquo=
te 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>Stretch this idea=
s of this proposal a little bit and you can vision definitions being redecl=
ared this way and used in C++ instead of the legacy macros which in turn co=
uld get deprecated over time (of course, if C support is to be dropped). Th=
e author of this proposal can see derivations of such work aiding with a be=
tter support modules in legacy environments too.</div></div></blockquote><d=
iv><br></div><div>I don&#39;t understand how encouraging macro metaprogramm=
ing would in any way lead to the &quot;deprecation&quot; of &quot;legacy ma=
cros&quot;. If I understand correctly, you&#39;re asking for the legacy mac=
ro system to be <i>strengthened</i> to the point where working programmers =
are using it to do metaprogramming even in C++. The general party line in C=
++ today is that working programmers should not be using preprocessor macro=
s for just about anything, because we have semantically safer versions of t=
he same toolkit that are not based on textual substitution: enums, inline f=
unctions, pass-by-reference,...</div><div>=C2=A0<br></div><blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;"><div dir=3D"ltr"><div>If such functionality can=
 already be achieved using already available techniques, I&#39;d love to he=
ar more.<br></div></div></blockquote><div><br></div><div>I&#39;d point you =
to approaches A, B, and C above.</div><div><br></div><div>=E2=80=93Arthur</=
div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; 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/8ca43f3a-344d-4844-af5e-04898173e11f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/8ca43f3a-344d-4844-af5e-04898173e11f=
%40isocpp.org</a>.<br />

------=_Part_1585_313722150.1481679371309--

------=_Part_1584_1277808112.1481679371308--

.