Topic: Raw" preprocessor macro arguments
Author: Vittorio Romeo <vittorio.romeo.vee@gmail.com>
Date: Sun, 19 Jan 2014 09:28:43 -0800 (PST)
Raw View
------=_Part_333_8680371.1390152523746
Content-Type: text/plain; charset=UTF-8
*Preprocessor macros*, even if potentially *unsafe*, still have place in a
lot of C/C++ programs. Using macros is the sometimes only way to avoid
verbose code repetition, to simulate static reflection or to generate code
that would be impossible to generate only using templates.
An issue with macros is that passing arguments is sometimes really
counter-intuitive and dangerous.
Example:
#define GENERATE_FUNC(mType, mName, mBody) mType mName(){ mBody }
// Ok, generates valid code
GENERATE_FUNC(void, printHi, printf("hi");)
// Ok, generates valid code
GENERATE_FUNC(void, printNumber, printf("%d", 5);)
// The comma in "<int, int>" is read as an additional argument - macro
expansion fails
GENERATE_FUNC(std::pair<int, int>, getPair1, return std::make_pair(1, 1);)
// The comma in "<int, int>" is read correctly, but the generated code is
invalid, as
// the round parenthesis persist in the return type (look below for the
expansion)
GENERATE_FUNC((std::pair<int, int>), getPair2, return std::make_pair(1, 1);)
/*
(std::pair<int, int>) getPair2() { return std::make_pair(1, 1); }
*/
There are possible solutions to this issue:
1. Create a typedef for `std::pair<int, int>` - this solution is specific
to this case, and may not always be applicable. Additionally, it requires
the coder to define a new typedef,
2. Create multiple macros (for example, GENERATE_FUNC_START and
GENERATE_FUNC_END), and let the user write the code in-between - this
solution is ugly and error prone. Also, it scales poorly, as k "body"
arguments would require k+1 macro definitions.
These solutions, however, can be defined *hacks. *The issue is that there
is no way to pass a "raw" argument to the preprocessor.
Here's what I propose:
*Similarly to C++11 raw strings, have a new syntax that allows the user to
pass "raw arguments" to preprocessor macros.*
Example:
GENERATE_FUNC(__R(std::pair<int, int>), __R(getPairRaw), __R(return std::
make_pair(1, 1))
Specification:
< __R > <prefix> <(> <...> <)> <suffix>
Prefix/suffix example:
GENERATE_FUNC(__R***(ReturnType(int*))***, __R(getIntPtr), __R(return &
someInt;))
Unit test before example:
UNIT_TEST_START()
EXPECT(some predicate);
...
UNIT_TEST_END()
Unit test after example:
UNIT_TEST(__R(
EXPECT(some predicate);
...
))
This "raw syntax" would also fix the "comma problem", that forced users to
define a "COMMA" macro for years:
__R(,)
*What do you think?*
--
---
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_333_8680371.1390152523746
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><b>Preprocessor macros</b>, even if potentially =
<i>unsafe</i>, still have place in a lot of C/C++ programs. Using macros is=
the sometimes only way to avoid verbose code repetition, to simulate stati=
c reflection or to generate code that would be impossible to generate only =
using templates.<div>An issue with macros is that passing arguments is some=
times really counter-intuitive and dangerous. <br><br>Example:</div><d=
iv><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-prettify">#define</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> GENERATE_FUNC</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">mType</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> mName</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> mB=
ody</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> mType mName</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(){</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> mBody </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br><br><br></span><span style=3D=
"color: #800;" class=3D"styled-by-prettify">// Ok, generates valid code</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>GENERATE_F=
UNC</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> printHi</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> printf</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">(</span><span style=3D"color: #080;" class=3D=
"styled-by-prettify">"hi"</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">);)</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br><br><br></span><span style=3D"color: #800;" class=3D"styled-by-=
prettify">// Ok, generates valid code</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>GENERATE_FUNC</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">void</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> printNumber</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> printf</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #080;" class=3D"styled-by-prettify">"%d"</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #066;" class=3D"styled-by-prettify">5</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">);)</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br><br><br></span><span style=3D"color: #800;" c=
lass=3D"styled-by-prettify">// The comma in "<int, int>" is read as a=
n additional argument - macro expansion fails</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>GENERATE_FUNC</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">std</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">pair</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">int</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">>,</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> getPair1</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: #008;" clas=
s=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">make_pair</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #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><br><br></span><span style=3D"color: #80=
0;" class=3D"styled-by-prettify">// The comma in "<int, int>" is read=
correctly, but the generated code is invalid, as </span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #8=
00;" class=3D"styled-by-prettify">// the round parenthesis persist in the r=
eturn type (look below for the expansion)</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br>GENERATE_FUNC</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">((</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">pair</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">int</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=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: #000;" class=3D"styled-by-prettify"> getPair2</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">make_pair</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</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: #066;" class=3D"styled-by-prettify">1</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">);)</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">/*<br> (std::pair<int, int>) get=
Pair2() { return std::make_pair(1, 1); }<br>*/</span></div></code></div><di=
v><br></div></div><div>There are possible solutions to this issue:</div>1. =
Create a typedef for `std::pair<int, int>` - this solution is specifi=
c to this case, and may not always be applicable. Additionally, it requires=
the coder to define a new typedef,<div>2. Create multiple macros (for exam=
ple, GENERATE_FUNC_START and GENERATE_FUNC_END), and let the user write the=
code in-between - this solution is ugly and error prone. Also, it scales p=
oorly, as k "body" arguments would require k+1 macro definitions.</div><div=
><br></div><div>These solutions, however, can be defined <i>hacks. </i>The =
issue is that there is no way to pass a "raw" argument to the preprocessor.=
</div><div><br></div><div>Here's what I propose:</div><div><b>Similar=
ly to C++11 raw strings, have a new syntax that allows the user to pass "ra=
w arguments" to preprocessor macros.</b></div><div><br></div><div>Example:<=
/div><div><div class=3D"prettyprint" style=3D"background-color: rgb(250, 25=
0, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-word;"><cod=
e class=3D"prettyprint"><div class=3D"subprettyprint"><font color=3D"#00000=
0"><span style=3D"color: #000;" class=3D"styled-by-prettify">GENERATE_FUNC<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">__R</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">std</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">pair</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify"><</span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">>),</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> __R</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">getPairRaw</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">),</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> __R</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">mak=
e_pair</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #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"> </span><span style=3D"color: #=
066;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">))</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span></font></div></code></div><br>Specification:</=
div><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"><font color=3D"#660066=
"><span style=3D"color: #000;" class=3D"styled-by-prettify">< __R > <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify"><prefix&=
gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <(&=
gt; <...> <)> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify"><suffix></span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span></font></div></code></div><br>Prefix/suffix exa=
mple:</div><div><div class=3D"prettyprint" style=3D"background-color: rgb(2=
50, 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: #000;" class=3D"styled-by-prettify">GENERATE_FUNC</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">__R</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">***(</span><span style=3D"color: #606;" clas=
s=3D"styled-by-prettify">ReturnType</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">*))***,</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> __R</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">getIntPtr=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">),</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> __R</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&</span><font color=3D"#006666"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">someInt</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></font></div></code></di=
v><br></div><div>Unit test before example:</div><div><div class=3D"prettypr=
int" style=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(1=
87, 187, 187); word-wrap: break-word;"><code class=3D"prettyprint"><div cla=
ss=3D"subprettyprint"><font color=3D"#660066"><span style=3D"color: #000;" =
class=3D"styled-by-prettify">UNIT_TEST_START</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br></span></font><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> EXPECT</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">some predicate</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><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> <br></span><font color=3D"#660066"><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">UNIT_TEST_END</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span></font>=
</div></code></div><br></div><div>Unit test after example:</div><div><div c=
lass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border:=
1px solid rgb(187, 187, 187); word-wrap: break-word;"><code class=3D"prett=
yprint"><div class=3D"subprettyprint"><font color=3D"#660066"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">UNIT_TEST</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">__R</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br> EXPECT</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">some predicate</span><span style=3D"colo=
r: #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"col=
or: #000;" class=3D"styled-by-prettify"> <br></span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">))</span></font></div></code></div><br>T=
his "raw syntax" would also fix the "comma problem", that forced users to d=
efine a "COMMA" macro for years:</div><div><div class=3D"prettyprint" style=
=3D"background-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 1=
87); word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><font color=3D"#660066"><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">__R</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">(,)</span></font></div></code></div><br><b>What do you think?</=
b></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 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 />
------=_Part_333_8680371.1390152523746--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sun, 19 Jan 2014 20:24:50 +0200
Raw View
On 19 January 2014 19:28, Vittorio Romeo <vittorio.romeo.vee@gmail.com> wrote:
> This "raw syntax" would also fix the "comma problem", that forced users to
> define a "COMMA" macro for years:
> __R(,)
>
> What do you think?
It certainly seems like a useful facility to have. I expect
resistance, and I expect
an argument "we need to get this into the preprocessor spec of C first, and
if we don't get it there, we don't want it in C++". I may be wrong in that
expectation, though.
--
---
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/.
.
Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Sun, 19 Jan 2014 13:11:35 -0800 (PST)
Raw View
------=_Part_411_15966508.1390165895400
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
#define RAW(x) x
GENERATE_FUNC(RAW(std::pair<int, int>), getPair1), return std::make_pair(1,=
=20
1));
The arguments to a macro are identified before macro expansion takes place=
=20
on the arguments. So the above will nest out the comma like you want.
The preprocessor respects parenthesis for nesting arguments.
From 16.2:
The sequence of preprocessing tokens bounded by the outside-most matching=
=20
parentheses forms the list of
arguments for the function-like macro. The individual arguments within the=
=20
list are separated by comma
preprocessing tokens, *but comma preprocessing tokens between matching=20
inner parentheses do not separate*
*arguments*.
*After the arguments for the invocation of a function-like macro have been=
=20
identi=EF=AC=81ed, argument substitution*
*takes place.* A parameter in the replacement list, unless preceded by a #=
=20
or ## preprocessing token or
followed by a ## preprocessing token (see below), is replaced by the=20
corresponding argument after all macros
contained therein have been expanded. Before being substituted, each=20
argument=E2=80=99s preprocessing tokens are
completely macro replaced as if they formed the rest of the preprocessing=
=20
=EF=AC=81le; no other preprocessing tokens
are available.
On Sunday, January 19, 2014 6:28:43 PM UTC+1, Vittorio Romeo wrote:
>
> *Preprocessor macros*, even if potentially *unsafe*, still have place in=
=20
> a lot of C/C++ programs. Using macros is the sometimes only way to avoid=
=20
> verbose code repetition, to simulate static reflection or to generate cod=
e=20
> that would be impossible to generate only using templates.
> An issue with macros is that passing arguments is sometimes really=20
> counter-intuitive and dangerous.=20
>
> Example:
> #define GENERATE_FUNC(mType, mName, mBody) mType mName(){ mBody }
>
>
> // Ok, generates valid code
> GENERATE_FUNC(void, printHi, printf("hi");)
>
>
> // Ok, generates valid code
> GENERATE_FUNC(void, printNumber, printf("%d", 5);)
>
>
> // The comma in "<int, int>" is read as an additional argument - macro=20
> expansion fails
> GENERATE_FUNC(std::pair<int, int>, getPair1, return std::make_pair(1, 1);=
)
>
>
> // The comma in "<int, int>" is read correctly, but the generated code is=
=20
> invalid, as=20
> // the round parenthesis persist in the return type (look below for the=
=20
> expansion)
> GENERATE_FUNC((std::pair<int, int>), getPair2, return std::make_pair(1, 1
> );)
> /*
> (std::pair<int, int>) getPair2() { return std::make_pair(1, 1); }
> */
>
> There are possible solutions to this issue:
> 1. Create a typedef for `std::pair<int, int>` - this solution is specific=
=20
> to this case, and may not always be applicable. Additionally, it requires=
=20
> the coder to define a new typedef,
> 2. Create multiple macros (for example, GENERATE_FUNC_START and=20
> GENERATE_FUNC_END), and let the user write the code in-between - this=20
> solution is ugly and error prone. Also, it scales poorly, as k "body"=20
> arguments would require k+1 macro definitions.
>
> These solutions, however, can be defined *hacks. *The issue is that there=
=20
> is no way to pass a "raw" argument to the preprocessor.=20
>
> Here's what I propose:
> *Similarly to C++11 raw strings, have a new syntax that allows the user t=
o=20
> pass "raw arguments" to preprocessor macros.*
>
> Example:
> GENERATE_FUNC(__R(std::pair<int, int>), __R(getPairRaw), __R(return std::
> make_pair(1, 1))
>
> Specification:
> < __R > <prefix> <(> <...> <)> <suffix>=20
>
> Prefix/suffix example:
> GENERATE_FUNC(__R***(ReturnType(int*))***, __R(getIntPtr), __R(return &
> someInt;))
>
> Unit test before example:
> UNIT_TEST_START()
> EXPECT(some predicate);
> ...=20
> UNIT_TEST_END()
>
> Unit test after example:
> UNIT_TEST(__R(
> EXPECT(some predicate);
> ...=20
> ))
>
> This "raw syntax" would also fix the "comma problem", that forced users t=
o=20
> define a "COMMA" macro for years:
> __R(,)
>
> *What do you think?*
>
--=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/.
------=_Part_411_15966508.1390165895400
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">#define RAW(x) x<div><br></div><div><span style=3D"font-fa=
mily: monospace; background-color: rgb(250, 250, 250); color: rgb(0, 0, 0);=
">GENERATE_FUNC</span><span style=3D"font-family: monospace; background-col=
or: rgb(250, 250, 250); color: rgb(102, 102, 0);">(RAW(</span><span style=
=3D"font-family: monospace; background-color: rgb(250, 250, 250); color: rg=
b(0, 0, 0);">std</span><span style=3D"font-family: monospace; background-co=
lor: rgb(250, 250, 250); color: rgb(102, 102, 0);">::</span><span style=3D"=
font-family: monospace; background-color: rgb(250, 250, 250); color: rgb(0,=
0, 0);">pair</span><span style=3D"font-family: monospace; background-color=
: rgb(250, 250, 250); color: rgb(102, 102, 0);"><</span><span style=3D"f=
ont-family: monospace; background-color: rgb(250, 250, 250); color: rgb(0, =
0, 136);">int</span><span style=3D"font-family: monospace; background-color=
: rgb(250, 250, 250); color: rgb(102, 102, 0);">,</span><span style=3D"font=
-family: monospace; background-color: rgb(250, 250, 250); color: rgb(0, 0, =
0);"> </span><span style=3D"font-family: monospace; background-color: =
rgb(250, 250, 250); color: rgb(0, 0, 136);">int</span><span style=3D"font-f=
amily: monospace; background-color: rgb(250, 250, 250); color: rgb(102, 102=
, 0);">>),</span><span style=3D"font-family: monospace; background-color=
: rgb(250, 250, 250); color: rgb(0, 0, 0);"> getPair1)</span><span sty=
le=3D"font-family: monospace; background-color: rgb(250, 250, 250); color: =
rgb(102, 102, 0);">,</span><span style=3D"font-family: monospace; backgroun=
d-color: rgb(250, 250, 250); color: rgb(0, 0, 0);"> </span><span style=
=3D"font-family: monospace; background-color: rgb(250, 250, 250); color: rg=
b(0, 0, 136);">return</span><span style=3D"font-family: monospace; backgrou=
nd-color: rgb(250, 250, 250); color: rgb(0, 0, 0);"> std</span><span s=
tyle=3D"font-family: monospace; background-color: rgb(250, 250, 250); color=
: rgb(102, 102, 0);">::</span><span style=3D"font-family: monospace; backgr=
ound-color: rgb(250, 250, 250); color: rgb(0, 0, 0);">make_pair</span><span=
style=3D"font-family: monospace; background-color: rgb(250, 250, 250); col=
or: rgb(102, 102, 0);">(</span><span style=3D"font-family: monospace; backg=
round-color: rgb(250, 250, 250); color: rgb(0, 102, 102);">1</span><span st=
yle=3D"font-family: monospace; background-color: rgb(250, 250, 250); color:=
rgb(102, 102, 0);">,</span><span style=3D"font-family: monospace; backgrou=
nd-color: rgb(250, 250, 250); color: rgb(0, 0, 0);"> </span><span styl=
e=3D"font-family: monospace; background-color: rgb(250, 250, 250); color: r=
gb(0, 102, 102);">1</span><span style=3D"font-family: monospace; background=
-color: rgb(250, 250, 250);"><font color=3D"#666600">));</font></span><br><=
/div><div><br></div><div>The arguments to a macro are identified before mac=
ro expansion takes place on the arguments. So the above will nest out=
the comma like you want.</div><div><br></div><div>The preprocessor respect=
s parenthesis for nesting arguments.</div><div><br></div><div>From 16.2:</d=
iv><div><br><div>The sequence of preprocessing tokens bounded by the outsid=
e-most matching parentheses forms the list of</div><div>arguments for the f=
unction-like macro. The individual arguments within the list are separated =
by comma</div><div>preprocessing tokens, <b>but comma preprocessing tokens =
between matching inner parentheses do not separate</b></div><div><b>argumen=
ts</b>.</div><div><br></div><div><div><b>After the arguments for the invoca=
tion of a function-like macro have been identi=EF=AC=81ed, argument substit=
ution</b></div><div><b>takes place.</b> A parameter in the replacement list=
, unless preceded by a # or ## preprocessing token or</div><div>followed by=
a ## preprocessing token (see below), is replaced by the corresponding arg=
ument after all macros</div><div>contained therein have been expanded. Befo=
re being substituted, each argument=E2=80=99s preprocessing tokens are</div=
><div>completely macro replaced as if they formed the rest of the preproces=
sing =EF=AC=81le; no other preprocessing tokens</div><div>are available.</d=
iv></div><div><br></div>On Sunday, January 19, 2014 6:28:43 PM UTC+1, Vitto=
rio Romeo 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"lt=
r"><b>Preprocessor macros</b>, even if potentially <i>unsafe</i>,=
still have place in a lot of C/C++ programs. Using macros is the sometimes=
only way to avoid verbose code repetition, to simulate static reflection o=
r to generate code that would be impossible to generate only using template=
s.<div>An issue with macros is that passing arguments is sometimes really c=
ounter-intuitive and dangerous. <br><br>Example:</div><div><div style=
=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,187);wor=
d-wrap:break-word"><code><div><span style=3D"color:#800">#define</span><spa=
n style=3D"color:#000"> GENERATE_FUNC</span><span style=3D"color:#660">(</s=
pan><span style=3D"color:#000">mType</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000"> mName</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000"> mBody</span><span style=3D"color:#660">)</sp=
an><span style=3D"color:#000"> mType mName</span><span style=3D"color:#660"=
>(){</span><span style=3D"color:#000"> mBody </span><span style=3D"color:#6=
60">}</span><span style=3D"color:#000"><br><br><br></span><span style=3D"co=
lor:#800">// Ok, generates valid code</span><span style=3D"color:#000"><br>=
GENERATE_FUNC</span><span style=3D"color:#660">(</span><span style=3D"color=
:#008">void</span><span style=3D"color:#660">,</span><span style=3D"color:#=
000"> printHi</span><span style=3D"color:#660">,</span><span style=3D"color=
:#000"> printf</span><span style=3D"color:#660">(</span><span style=3D"colo=
r:#080">"hi"</span><span style=3D"color:#660">);)</span><span style=3D"colo=
r:#000"><br><br><br></span><span style=3D"color:#800">// Ok, generates vali=
d code</span><span style=3D"color:#000"><br>GENERATE_FUNC</span><span style=
=3D"color:#660">(</span><span style=3D"color:#008">void</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> printNumber</span><span=
style=3D"color:#660">,</span><span style=3D"color:#000"> printf</span><spa=
n style=3D"color:#660">(</span><span style=3D"color:#080">"%d"</span><span =
style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#066">5</span><span style=3D"color:#660">);)</span><span style=3D=
"color:#000"><br><br><br></span><span style=3D"color:#800">// The comma in =
"<int, int>" is read as an additional argument - macro expansion fail=
s</span><span style=3D"color:#000"><br>GENERATE_FUNC</span><span style=3D"c=
olor:#660">(</span><span style=3D"color:#000">std</span><span style=3D"colo=
r:#660">::</span><span style=3D"color:#000">pair</span><span style=3D"color=
:#660"><</span><span style=3D"color:#008">int</span><span style=3D"color=
:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#008=
">int</span><span style=3D"color:#660">>,</span><span style=3D"color:#00=
0"> getPair1</span><span style=3D"color:#660">,</span><span style=3D"color:=
#000"> </span><span style=3D"color:#008">return</span><span style=3D"color:=
#000"> std</span><span style=3D"color:#660">::</span><span style=3D"color:#=
000">make_pair</span><span style=3D"color:#660">(</span><span style=3D"colo=
r:#066">1</span><span style=3D"color:#660">,</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#066">1</span><span style=3D"color:#660">);=
)</span><span style=3D"color:#000"><br><br><br></span><span style=3D"color:=
#800">// The comma in "<int, int>" is read correctly, but the generat=
ed code is invalid, as </span><span style=3D"color:#000"><br></span><span s=
tyle=3D"color:#800">// the round parenthesis persist in the return type (lo=
ok below for the expansion)</span><span style=3D"color:#000"><br>GENERATE_F=
UNC</span><span style=3D"color:#660">((</span><span style=3D"color:#000">st=
d</span><span style=3D"color:#660">::</span><span style=3D"color:#000">pair=
</span><span style=3D"color:#660"><</span><span style=3D"color:#008">int=
</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#008">int</span><span style=3D"color:#660">>),</s=
pan><span style=3D"color:#000"> getPair2</span><span style=3D"color:#660">,=
</span><span style=3D"color:#000"> </span><span style=3D"color:#008">return=
</span><span style=3D"color:#000"> std</span><span style=3D"color:#660">::<=
/span><span style=3D"color:#000">make_pair</span><span style=3D"color:#660"=
>(</span><span style=3D"color:#066">1</span><span style=3D"color:#660">,</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#066">1</span><=
span style=3D"color:#660">);)</span><span style=3D"color:#000"><br></span><=
span style=3D"color:#800">/*<br> (std::pair<int, int>) g=
etPair2() { return std::make_pair(1, 1); }<br>*/</span></div></code></div><=
div><br></div></div><div>There are possible solutions to this issue:</div>1=
.. Create a typedef for `std::pair<int, int>` - this solution is speci=
fic to this case, and may not always be applicable. Additionally, it requir=
es the coder to define a new typedef,<div>2. Create multiple macros (for ex=
ample, GENERATE_FUNC_START and GENERATE_FUNC_END), and let the user write t=
he code in-between - this solution is ugly and error prone. Also, it scales=
poorly, as k "body" arguments would require k+1 macro definitions.</div><d=
iv><br></div><div>These solutions, however, can be defined <i>hacks. </i>Th=
e issue is that there is no way to pass a "raw" argument to the preprocesso=
r. </div><div><br></div><div>Here's what I propose:</div><div><b>Simil=
arly to C++11 raw strings, have a new syntax that allows the user to pass "=
raw arguments" to preprocessor macros.</b></div><div><br></div><div>Example=
:</div><div><div style=3D"background-color:rgb(250,250,250);border:1px soli=
d rgb(187,187,187);word-wrap:break-word"><code><div><font color=3D"#000000"=
><span style=3D"color:#000">GENERATE_FUNC</span><span style=3D"color:#660">=
(</span><span style=3D"color:#000">__R</span><span style=3D"color:#660">(</=
span><span style=3D"color:#000">std</span><span style=3D"color:#660">::</sp=
an><span style=3D"color:#000">pair</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#008">in<wbr>t</span><span style=3D"color:#660">,<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">int</sp=
an><span style=3D"color:#660">>),</span><span style=3D"color:#000"> __R<=
/span><span style=3D"color:#660">(</span><span style=3D"color:#000">getPair=
Raw</span><span style=3D"color:#660">),</span><span style=3D"color:#000"> _=
_R</span><span style=3D"color:#660">(</span><span style=3D"color:#008">retu=
rn</span><span style=3D"color:#000"> std</span><span style=3D"color:#660">:=
:</span><span style=3D"color:#000">make_pair</span><span style=3D"color:#66=
0">(</span><span style=3D"color:#066">1</span><span style=3D"color:#660">,<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#066">1</span=
><span style=3D"color:#660">))</span><span style=3D"color:#000"><br></span>=
</font></div></code></div><br>Specification:</div><div><div style=3D"backgr=
ound-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:bre=
ak-word"><code><div><font color=3D"#660066"><span style=3D"color:#000"><=
__R > </span><span style=3D"color:#008"><prefix></span><span styl=
e=3D"color:#000"> <(> <...> <)> </span><span style=3D"col=
or:#008"><suffix></span><span style=3D"color:#000"> </span></font></d=
iv></code></div><br>Prefix/suffix example:</div><div><div style=3D"backgrou=
nd-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:break=
-word"><code><div><span style=3D"color:#000">GENERATE_FUNC</span><span styl=
e=3D"color:#660">(</span><span style=3D"color:#000">__R</span><span style=
=3D"color:#660">***(</span><span style=3D"color:#606">ReturnTyp<wbr>e</span=
><span style=3D"color:#660">(</span><span style=3D"color:#008">int</span><s=
pan style=3D"color:#660">*))***,</span><span style=3D"color:#000"> __R</spa=
n><span style=3D"color:#660">(</span><span style=3D"color:#000">getIntPtr</=
span><span style=3D"color:#660">),</span><span style=3D"color:#000"> __R</s=
pan><span style=3D"color:#660">(</span><span style=3D"color:#008">return</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">&</sp=
an><font color=3D"#006666"><span style=3D"color:#000">someInt</span><span s=
tyle=3D"color:#660">;))</span><span style=3D"color:#000"><br></span></font>=
</div></code></div><br></div><div>Unit test before example:</div><div><div =
style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,187=
);word-wrap:break-word"><code><div><font color=3D"#660066"><span style=3D"c=
olor:#000">UNIT_TEST_START</span><span style=3D"color:#660">()</span><span =
style=3D"color:#000"><br></span></font><span style=3D"color:#000"> &n=
bsp; EXPECT</span><span style=3D"color:#660">(</span><span style=3D"c=
olor:#000">some predicate</span><span style=3D"color:#660">);</span><span s=
tyle=3D"color:#000"><br> </span><span style=3D"color:#66=
0">...</span><span style=3D"color:#000"> <br></span><font color=3D"#660066"=
><span style=3D"color:#000">UNIT_TEST_END</span><span style=3D"color:#660">=
()</span></font></div></code></div><br></div><div>Unit test after example:<=
/div><div><div style=3D"background-color:rgb(250,250,250);border:1px solid =
rgb(187,187,187);word-wrap:break-word"><code><div><font color=3D"#660066"><=
span style=3D"color:#000">UNIT_TEST</span><span style=3D"color:#660">(</spa=
n><span style=3D"color:#000">__R</span><span style=3D"color:#660">(</span><=
span style=3D"color:#000"><br> EXPECT</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">some predicate</span><sp=
an style=3D"color:#660">);</span><span style=3D"color:#000"><br> &nbs=
p; </span><span style=3D"color:#660">...</span><span style=3D"color:#=
000"> <br></span><span style=3D"color:#660">))</span></font></div></code></=
div><br>This "raw syntax" would also fix the "comma problem", that forced u=
sers to define a "COMMA" macro for years:</div><div><div style=3D"backgroun=
d-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:break-=
word"><code><div><font color=3D"#660066"><span style=3D"color:#000">__R</sp=
an><span style=3D"color:#660">(,)</span></font></div></code></div><br><b>Wh=
at do you think?</b></div></div></blockquote></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 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 />
------=_Part_411_15966508.1390165895400--
.
Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Sun, 19 Jan 2014 14:15:46 -0800 (PST)
Raw View
------=_Part_552_24779971.1390169746827
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Actually sorry, I am slightly wrong about that solution. The argument to=
=20
RAW will be parsed in turn as two arguments and not one. It should be:
#define RAW(...) __VA_ARGS__
This will work I think.
On Sunday, January 19, 2014 10:11:35 PM UTC+1, Andrew Tomazos wrote:
>
> #define RAW(x) x
>
> GENERATE_FUNC(RAW(std::pair<int, int>), getPair1), return std::make_pair(=
1
> , 1));
>
> The arguments to a macro are identified before macro expansion takes plac=
e=20
> on the arguments. So the above will nest out the comma like you want.
>
> The preprocessor respects parenthesis for nesting arguments.
>
> From 16.2:
>
> The sequence of preprocessing tokens bounded by the outside-most matching=
=20
> parentheses forms the list of
> arguments for the function-like macro. The individual arguments within th=
e=20
> list are separated by comma
> preprocessing tokens, *but comma preprocessing tokens between matching=20
> inner parentheses do not separate*
> *arguments*.
>
> *After the arguments for the invocation of a function-like macro have bee=
n=20
> identi=EF=AC=81ed, argument substitution*
> *takes place.* A parameter in the replacement list, unless preceded by a=
=20
> # or ## preprocessing token or
> followed by a ## preprocessing token (see below), is replaced by the=20
> corresponding argument after all macros
> contained therein have been expanded. Before being substituted, each=20
> argument=E2=80=99s preprocessing tokens are
> completely macro replaced as if they formed the rest of the preprocessing=
=20
> =EF=AC=81le; no other preprocessing tokens
> are available.
>
> On Sunday, January 19, 2014 6:28:43 PM UTC+1, Vittorio Romeo wrote:
>>
>> *Preprocessor macros*, even if potentially *unsafe*, still have place in=
=20
>> a lot of C/C++ programs. Using macros is the sometimes only way to avoid=
=20
>> verbose code repetition, to simulate static reflection or to generate co=
de=20
>> that would be impossible to generate only using templates.
>> An issue with macros is that passing arguments is sometimes really=20
>> counter-intuitive and dangerous.=20
>>
>> Example:
>> #define GENERATE_FUNC(mType, mName, mBody) mType mName(){ mBody }
>>
>>
>> // Ok, generates valid code
>> GENERATE_FUNC(void, printHi, printf("hi");)
>>
>>
>> // Ok, generates valid code
>> GENERATE_FUNC(void, printNumber, printf("%d", 5);)
>>
>>
>> // The comma in "<int, int>" is read as an additional argument - macro=
=20
>> expansion fails
>> GENERATE_FUNC(std::pair<int, int>, getPair1, return std::make_pair(1, 1
>> );)
>>
>>
>> // The comma in "<int, int>" is read correctly, but the generated code i=
s=20
>> invalid, as=20
>> // the round parenthesis persist in the return type (look below for the=
=20
>> expansion)
>> GENERATE_FUNC((std::pair<int, int>), getPair2, return std::make_pair(1, =
1
>> );)
>> /*
>> (std::pair<int, int>) getPair2() { return std::make_pair(1, 1); }
>> */
>>
>> There are possible solutions to this issue:
>> 1. Create a typedef for `std::pair<int, int>` - this solution is specifi=
c=20
>> to this case, and may not always be applicable. Additionally, it require=
s=20
>> the coder to define a new typedef,
>> 2. Create multiple macros (for example, GENERATE_FUNC_START and=20
>> GENERATE_FUNC_END), and let the user write the code in-between - this=20
>> solution is ugly and error prone. Also, it scales poorly, as k "body"=20
>> arguments would require k+1 macro definitions.
>>
>> These solutions, however, can be defined *hacks. *The issue is that=20
>> there is no way to pass a "raw" argument to the preprocessor.=20
>>
>> Here's what I propose:
>> *Similarly to C++11 raw strings, have a new syntax that allows the user=
=20
>> to pass "raw arguments" to preprocessor macros.*
>>
>> Example:
>> GENERATE_FUNC(__R(std::pair<int, int>), __R(getPairRaw), __R(return std:=
:
>> make_pair(1, 1))
>>
>> Specification:
>> < __R > <prefix> <(> <...> <)> <suffix>=20
>>
>> Prefix/suffix example:
>> GENERATE_FUNC(__R***(ReturnType(int*))***, __R(getIntPtr), __R(return &
>> someInt;))
>>
>> Unit test before example:
>> UNIT_TEST_START()
>> EXPECT(some predicate);
>> ...=20
>> UNIT_TEST_END()
>>
>> Unit test after example:
>> UNIT_TEST(__R(
>> EXPECT(some predicate);
>> ...=20
>> ))
>>
>> This "raw syntax" would also fix the "comma problem", that forced users=
=20
>> to define a "COMMA" macro for years:
>> __R(,)
>>
>> *What do you think?*
>>
>
--=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/.
------=_Part_552_24779971.1390169746827
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Actually sorry, I am slightly wrong about that solution. &=
nbsp;The argument to RAW will be parsed in turn as two arguments and not on=
e. It should be:<div><br></div><div> #define RAW(...) __=
VA_ARGS__<br><br>This will work I think.</div><div><br></div><div>On Sunday=
, January 19, 2014 10:11:35 PM UTC+1, Andrew Tomazos wrote:<blockquote clas=
s=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #c=
cc solid;padding-left: 1ex;"><div dir=3D"ltr">#define RAW(x) x<div><br></di=
v><div><span style=3D"font-family:monospace;background-color:rgb(250,250,25=
0);color:rgb(0,0,0)">GENERATE_FUNC</span><span style=3D"font-family:monospa=
ce;background-color:rgb(250,250,250);color:rgb(102,102,0)">(RAW(</span><spa=
n style=3D"font-family:monospace;background-color:rgb(250,250,250);color:rg=
b(0,0,0)">std</span><span style=3D"font-family:monospace;background-color:r=
gb(250,250,250);color:rgb(102,102,0)">::</span><span style=3D"font-family:m=
onospace;background-color:rgb(250,250,250);color:rgb(0,0,0)">pair</span><sp=
an style=3D"font-family:monospace;background-color:rgb(250,250,250);color:r=
gb(102,102,0)"><</span><span style=3D"font-family:monospace;background-c=
olor:rgb(250,250,250);color:rgb(0,0,136)">in<wbr>t</span><span style=3D"fon=
t-family:monospace;background-color:rgb(250,250,250);color:rgb(102,102,0)">=
,</span><span style=3D"font-family:monospace;background-color:rgb(250,250,2=
50);color:rgb(0,0,0)"> </span><span style=3D"font-family:monospace;bac=
kground-color:rgb(250,250,250);color:rgb(0,0,136)">int</span><span style=3D=
"font-family:monospace;background-color:rgb(250,250,250);color:rgb(102,102,=
0)">>),</span><span style=3D"font-family:monospace;background-color:rgb(=
250,250,250);color:rgb(0,0,0)"> getPair1)</span><span style=3D"font-fa=
mily:monospace;background-color:rgb(250,250,250);color:rgb(102,102,0)">,</s=
pan><span style=3D"font-family:monospace;background-color:rgb(250,250,250);=
color:rgb(0,0,0)"> </span><span style=3D"font-family:monospace;backgro=
und-color:rgb(250,250,250);color:rgb(0,0,136)">return</span><span style=3D"=
font-family:monospace;background-color:rgb(250,250,250);color:rgb(0,0,0)">&=
nbsp;<wbr>std</span><span style=3D"font-family:monospace;background-color:r=
gb(250,250,250);color:rgb(102,102,0)">::</span><span style=3D"font-family:m=
onospace;background-color:rgb(250,250,250);color:rgb(0,0,0)">make_pair</spa=
n><span style=3D"font-family:monospace;background-color:rgb(250,250,250);co=
lor:rgb(102,102,0)">(</span><span style=3D"font-family:monospace;background=
-color:rgb(250,250,250);color:rgb(0,102,102)">1</span><span style=3D"font-f=
amily:monospace;background-color:rgb(250,250,250);color:rgb(102,102,0)">,</=
span><span style=3D"font-family:monospace;background-color:rgb(250,250,250)=
;color:rgb(0,0,0)"> </span><span style=3D"font-family:monospace;backgr=
ound-color:rgb(250,250,250);color:rgb(0,102,102)">1</span><span style=3D"fo=
nt-family:monospace;background-color:rgb(250,250,250)"><font color=3D"#6666=
00">));</font></span><br></div><div><br></div><div>The arguments to a macro=
are identified before macro expansion takes place on the arguments. =
So the above will nest out the comma like you want.</div><div><br></div><di=
v>The preprocessor respects parenthesis for nesting arguments.</div><div><b=
r></div><div>From 16.2:</div><div><br><div>The sequence of preprocessing to=
kens bounded by the outside-most matching parentheses forms the list of</di=
v><div>arguments for the function-like macro. The individual arguments with=
in the list are separated by comma</div><div>preprocessing tokens, <b>but c=
omma preprocessing tokens between matching inner parentheses do not separat=
e</b></div><div><b>arguments</b>.</div><div><br></div><div><div><b>After th=
e arguments for the invocation of a function-like macro have been identi=EF=
=AC=81ed, argument substitution</b></div><div><b>takes place.</b> A paramet=
er in the replacement list, unless preceded by a # or ## preprocessing toke=
n or</div><div>followed by a ## preprocessing token (see below), is replace=
d by the corresponding argument after all macros</div><div>contained therei=
n have been expanded. Before being substituted, each argument=E2=80=99s pre=
processing tokens are</div><div>completely macro replaced as if they formed=
the rest of the preprocessing =EF=AC=81le; no other preprocessing tokens</=
div><div>are available.</div></div><div><br></div>On Sunday, January 19, 20=
14 6:28:43 PM UTC+1, Vittorio Romeo wrote:<blockquote class=3D"gmail_quote"=
style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-lef=
t:1ex"><div dir=3D"ltr"><b>Preprocessor macros</b>, even if potentiall=
y <i>unsafe</i>, still have place in a lot of C/C++ programs. Using ma=
cros is the sometimes only way to avoid verbose code repetition, to simulat=
e static reflection or to generate code that would be impossible to generat=
e only using templates.<div>An issue with macros is that passing arguments =
is sometimes really counter-intuitive and dangerous. <br><br>Example:<=
/div><div><div style=3D"background-color:rgb(250,250,250);border:1px solid =
rgb(187,187,187);word-wrap:break-word"><code><div><span style=3D"color:#800=
">#define</span><span style=3D"color:#000"> GENERATE_FUNC</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">mType</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> mName</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> mBody</span><span style=
=3D"color:#660">)</span><span style=3D"color:#000"> mType mName</span><span=
style=3D"color:#660">(){</span><span style=3D"color:#000"> mBody </span><s=
pan style=3D"color:#660">}</span><span style=3D"color:#000"><br><br><br></s=
pan><span style=3D"color:#800">// Ok, generates valid code</span><span styl=
e=3D"color:#000"><br>GENERATE_FUNC</span><span style=3D"color:#660">(</span=
><span style=3D"color:#008">void</span><span style=3D"color:#660">,</span><=
span style=3D"color:#000"> printHi</span><span style=3D"color:#660">,</span=
><span style=3D"color:#000"> printf</span><span style=3D"color:#660">(</spa=
n><span style=3D"color:#080">"hi"</span><span style=3D"color:#660">);)</spa=
n><span style=3D"color:#000"><br><br><br></span><span style=3D"color:#800">=
// Ok, generates valid code</span><span style=3D"color:#000"><br>GENERATE_F=
UNC</span><span style=3D"color:#660">(</span><span style=3D"color:#008">voi=
d</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> prin=
tNumber</span><span style=3D"color:#660">,</span><span style=3D"color:#000"=
> printf</span><span style=3D"color:#660">(</span><span style=3D"color:#080=
">"%d"</span><span style=3D"color:#660">,</span><span style=3D"color:#000">=
</span><span style=3D"color:#066">5</span><span style=3D"color:#660">);)</=
span><span style=3D"color:#000"><br><br><br></span><span style=3D"color:#80=
0">// The comma in "<int, int>" is read as an additional argument - m=
acro expansion fails</span><span style=3D"color:#000"><br>GENERATE_FUNC</sp=
an><span style=3D"color:#660">(</span><span style=3D"color:#000">std</span>=
<span style=3D"color:#660">::</span><span style=3D"color:#000">pair</span><=
span style=3D"color:#660"><</span><span style=3D"color:#008">int</span><=
span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span =
style=3D"color:#008">int</span><span style=3D"color:#660">>,</span><span=
style=3D"color:#000"> getPair1</span><span style=3D"color:#660">,</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#008">return</span><s=
pan style=3D"color:#000"> std</span><span style=3D"color:#660">::</span><sp=
an style=3D"color:#000">make_pair</span><span style=3D"color:#660">(</span>=
<span style=3D"color:#066">1</span><span style=3D"color:#660">,</span><span=
style=3D"color:#000"> </span><span style=3D"color:#066">1</span><span styl=
e=3D"color:#660">);)</span><span style=3D"color:#000"><br><br><br></span><s=
pan style=3D"color:#800">// The comma in "<int, int>" is read correct=
ly, but the generated code is invalid, as </span><span style=3D"color:#000"=
><br></span><span style=3D"color:#800">// the round parenthesis persist in =
the return type (look below for the expansion)</span><span style=3D"color:#=
000"><br>GENERATE_FUNC</span><span style=3D"color:#660">((</span><span styl=
e=3D"color:#000">std</span><span style=3D"color:#660">::</span><span style=
=3D"color:#000">pair</span><span style=3D"color:#660"><</span><span styl=
e=3D"color:#008">int</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">int</span><span style=3D=
"color:#660">>),</span><span style=3D"color:#000"> getPair2</span><span =
style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">return</span><span style=3D"color:#000"> std</span><span st=
yle=3D"color:#660">::</span><span style=3D"color:#000">make_pair</span><spa=
n style=3D"color:#660">(</span><span style=3D"color:#066">1</span><span sty=
le=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D=
"color:#066">1</span><span style=3D"color:#660">);)</span><span style=3D"co=
lor:#000"><br></span><span style=3D"color:#800">/*<br> (std::p=
air<int, int>) getPair2() { return std::make_pair(1, 1); }<br>*/</spa=
n></div></code></div><div><br></div></div><div>There are possible solutions=
to this issue:</div>1. Create a typedef for `std::pair<int, int>` - =
this solution is specific to this case, and may not always be applicable. A=
dditionally, it requires the coder to define a new typedef,<div>2. Create m=
ultiple macros (for example, GENERATE_FUNC_START and GENERATE_FUNC_END), an=
d let the user write the code in-between - this solution is ugly and error =
prone. Also, it scales poorly, as k "body" arguments would require k+1 macr=
o definitions.</div><div><br></div><div>These solutions, however, can be de=
fined <i>hacks. </i>The issue is that there is no way to pass a "raw" argum=
ent to the preprocessor. </div><div><br></div><div>Here's what I propo=
se:</div><div><b>Similarly to C++11 raw strings, have a new syntax that all=
ows the user to pass "raw arguments" to preprocessor macros.</b></div><div>=
<br></div><div>Example:</div><div><div style=3D"background-color:rgb(250,25=
0,250);border:1px solid rgb(187,187,187);word-wrap:break-word"><code><div><=
font color=3D"#000000"><span style=3D"color:#000">GENERATE_FUNC</span><span=
style=3D"color:#660">(</span><span style=3D"color:#000">__R</span><span st=
yle=3D"color:#660">(</span><span style=3D"color:#000">std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">pair</span><span style=
=3D"color:#660"><</span><span style=3D"color:#008">in<wbr>t</span><span =
style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">int</span><span style=3D"color:#660">>),</span><span sty=
le=3D"color:#000"> __R</span><span style=3D"color:#660">(</span><span style=
=3D"color:#000">getPairRaw</span><span style=3D"color:#660">),</span><span =
style=3D"color:#000"> __R</span><span style=3D"color:#660">(</span><span st=
yle=3D"color:#008">return</span><span style=3D"color:#000"> std</span><span=
style=3D"color:#660">::</span><span style=3D"color:#000">make_pair</span><=
span style=3D"color:#660">(</span><span style=3D"color:#066">1</span><span =
style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#066">1</span><span style=3D"color:#660">))</span><span style=3D"=
color:#000"><br></span></font></div></code></div><br>Specification:</div><d=
iv><div style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187=
,187,187);word-wrap:break-word"><code><div><font color=3D"#660066"><span st=
yle=3D"color:#000">< __R > </span><span style=3D"color:#008"><pref=
ix></span><span style=3D"color:#000"> <(> <...> <)> </=
span><span style=3D"color:#008"><suffix></span><span style=3D"color:#=
000"> </span></font></div></code></div><br>Prefix/suffix example:</div><div=
><div style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,1=
87,187);word-wrap:break-word"><code><div><span style=3D"color:#000">GENERAT=
E_FUNC</span><span style=3D"color:#660">(</span><span style=3D"color:#000">=
__R</span><span style=3D"color:#660">***(</span><span style=3D"color:#606">=
ReturnTyp<wbr>e</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#008">int</span><span style=3D"color:#660">*))***,</span><span style=3D"=
color:#000"> __R</span><span style=3D"color:#660">(</span><span style=3D"co=
lor:#000">getIntPtr</span><span style=3D"color:#660">),</span><span style=
=3D"color:#000"> __R</span><span style=3D"color:#660">(</span><span style=
=3D"color:#008">return</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">&</span><font color=3D"#006666"><span style=3D"color:#0=
00">someInt</span><span style=3D"color:#660">;))</span><span style=3D"color=
:#000"><br></span></font></div></code></div><br></div><div>Unit test before=
example:</div><div><div style=3D"background-color:rgb(250,250,250);border:=
1px solid rgb(187,187,187);word-wrap:break-word"><code><div><font color=3D"=
#660066"><span style=3D"color:#000">UNIT_TEST_START</span><span style=3D"co=
lor:#660">()</span><span style=3D"color:#000"><br></span></font><span style=
=3D"color:#000"> EXPECT</span><span style=3D"color:#660"=
>(</span><span style=3D"color:#000">some predicate</span><span style=3D"col=
or:#660">);</span><span style=3D"color:#000"><br> </span=
><span style=3D"color:#660">...</span><span style=3D"color:#000"> <br></spa=
n><font color=3D"#660066"><span style=3D"color:#000">UNIT_TEST_END</span><s=
pan style=3D"color:#660">()</span></font></div></code></div><br></div><div>=
Unit test after example:</div><div><div style=3D"background-color:rgb(250,2=
50,250);border:1px solid rgb(187,187,187);word-wrap:break-word"><code><div>=
<font color=3D"#660066"><span style=3D"color:#000">UNIT_TEST</span><span st=
yle=3D"color:#660">(</span><span style=3D"color:#000">__R</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000"><br> =
EXPECT</span><span style=3D"color:#660">(</span><span style=3D"color:#000">=
some predicate</span><span style=3D"color:#660">);</span><span style=3D"col=
or:#000"><br> </span><span style=3D"color:#660">...</spa=
n><span style=3D"color:#000"> <br></span><span style=3D"color:#660">))</spa=
n></font></div></code></div><br>This "raw syntax" would also fix the "comma=
problem", that forced users to define a "COMMA" macro for years:</div><div=
><div style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,1=
87,187);word-wrap:break-word"><code><div><font color=3D"#660066"><span styl=
e=3D"color:#000">__R</span><span style=3D"color:#660">(,)</span></font></di=
v></code></div><br><b>What do you think?</b></div></div></blockquote></div>=
</div></blockquote></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 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 />
------=_Part_552_24779971.1390169746827--
.
Author: jgottman6@gmail.com
Date: Sun, 19 Jan 2014 17:06:18 -0800 (PST)
Raw View
------=_Part_550_15354894.1390179978103
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
I think this is still slightly wrong. Won't it eat the comma, so that=20
RAW(std::pair<int, int>)
becomes
std::pair<int int> //no comma!
Joe Gottman
On Sunday, January 19, 2014 5:15:46 PM UTC-5, Andrew Tomazos wrote:
>
> Actually sorry, I am slightly wrong about that solution. The argument to=
=20
> RAW will be parsed in turn as two arguments and not one. It should be:
>
> #define RAW(...) __VA_ARGS__
>
> This will work I think.
>
> On Sunday, January 19, 2014 10:11:35 PM UTC+1, Andrew Tomazos wrote:
>>
>> #define RAW(x) x
>>
>> GENERATE_FUNC(RAW(std::pair<int, int>), getPair1), return std::make_pair=
(
>> 1, 1));
>>
>> The arguments to a macro are identified before macro expansion takes=20
>> place on the arguments. So the above will nest out the comma like you w=
ant.
>>
>> The preprocessor respects parenthesis for nesting arguments.
>>
>> From 16.2:
>>
>> The sequence of preprocessing tokens bounded by the outside-most matchin=
g=20
>> parentheses forms the list of
>> arguments for the function-like macro. The individual arguments within=
=20
>> the list are separated by comma
>> preprocessing tokens, *but comma preprocessing tokens between matching=
=20
>> inner parentheses do not separate*
>> *arguments*.
>>
>> *After the arguments for the invocation of a function-like macro have=20
>> been identi=EF=AC=81ed, argument substitution*
>> *takes place.* A parameter in the replacement list, unless preceded by a=
=20
>> # or ## preprocessing token or
>> followed by a ## preprocessing token (see below), is replaced by the=20
>> corresponding argument after all macros
>> contained therein have been expanded. Before being substituted, each=20
>> argument=E2=80=99s preprocessing tokens are
>> completely macro replaced as if they formed the rest of the preprocessin=
g=20
>> =EF=AC=81le; no other preprocessing tokens
>> are available.
>>
>> On Sunday, January 19, 2014 6:28:43 PM UTC+1, Vittorio Romeo wrote:
>>>
>>> *Preprocessor macros*, even if potentially *unsafe*, still have place=
=20
>>> in a lot of C/C++ programs. Using macros is the sometimes only way to a=
void=20
>>> verbose code repetition, to simulate static reflection or to generate c=
ode=20
>>> that would be impossible to generate only using templates.
>>> An issue with macros is that passing arguments is sometimes really=20
>>> counter-intuitive and dangerous.=20
>>>
>>> Example:
>>> #define GENERATE_FUNC(mType, mName, mBody) mType mName(){ mBody }
>>>
>>>
>>> // Ok, generates valid code
>>> GENERATE_FUNC(void, printHi, printf("hi");)
>>>
>>>
>>> // Ok, generates valid code
>>> GENERATE_FUNC(void, printNumber, printf("%d", 5);)
>>>
>>>
>>> // The comma in "<int, int>" is read as an additional argument - macro=
=20
>>> expansion fails
>>> GENERATE_FUNC(std::pair<int, int>, getPair1, return std::make_pair(1, 1
>>> );)
>>>
>>>
>>> // The comma in "<int, int>" is read correctly, but the generated code=
=20
>>> is invalid, as=20
>>> // the round parenthesis persist in the return type (look below for the=
=20
>>> expansion)
>>> GENERATE_FUNC((std::pair<int, int>), getPair2, return std::make_pair(1,=
=20
>>> 1);)
>>> /*
>>> (std::pair<int, int>) getPair2() { return std::make_pair(1, 1); }
>>> */
>>>
>>> There are possible solutions to this issue:
>>> 1. Create a typedef for `std::pair<int, int>` - this solution is=20
>>> specific to this case, and may not always be applicable. Additionally, =
it=20
>>> requires the coder to define a new typedef,
>>> 2. Create multiple macros (for example, GENERATE_FUNC_START and=20
>>> GENERATE_FUNC_END), and let the user write the code in-between - this=
=20
>>> solution is ugly and error prone. Also, it scales poorly, as k "body"=
=20
>>> arguments would require k+1 macro definitions.
>>>
>>> These solutions, however, can be defined *hacks. *The issue is that=20
>>> there is no way to pass a "raw" argument to the preprocessor.=20
>>>
>>> Here's what I propose:
>>> *Similarly to C++11 raw strings, have a new syntax that allows the user=
=20
>>> to pass "raw arguments" to preprocessor macros.*
>>>
>>> Example:
>>> GENERATE_FUNC(__R(std::pair<int, int>), __R(getPairRaw), __R(return std
>>> ::make_pair(1, 1))
>>>
>>> Specification:
>>> < __R > <prefix> <(> <...> <)> <suffix>=20
>>>
>>> Prefix/suffix example:
>>> GENERATE_FUNC(__R***(ReturnType(int*))***, __R(getIntPtr), __R(return &
>>> someInt;))
>>>
>>> Unit test before example:
>>> UNIT_TEST_START()
>>> EXPECT(some predicate);
>>> ...=20
>>> UNIT_TEST_END()
>>>
>>> Unit test after example:
>>> UNIT_TEST(__R(
>>> EXPECT(some predicate);
>>> ...=20
>>> ))
>>>
>>> This "raw syntax" would also fix the "comma problem", that forced users=
=20
>>> to define a "COMMA" macro for years:
>>> __R(,)
>>>
>>> *What do you think?*
>>>
>>
--=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/.
------=_Part_550_15354894.1390179978103
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I think this is still slightly wrong. Won't it eat t=
he comma, so that <div class=3D"prettyprint" style=3D"background-color: rgb=
(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bor=
der-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div cl=
ass=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">RAW</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">pair</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify"><</span><span style=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: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">int</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">>)</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span></div></code></div>becomes<br><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: #000=
;" class=3D"styled-by-prettify">std</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">pair</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">></span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #800;" class=3D"styled-by-prettify">//no comma!</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><b=
r>Joe Gottman<br><br>On Sunday, January 19, 2014 5:15:46 PM UTC-5, Andrew T=
omazos wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">=
Actually sorry, I am slightly wrong about that solution. The argument=
to RAW will be parsed in turn as two arguments and not one. It shoul=
d be:<div><br></div><div> #define RAW(...) __VA_ARGS__<br><br>=
This will work I think.</div><div><br></div><div>On Sunday, January 19, 201=
4 10:11:35 PM UTC+1, Andrew Tomazos wrote:<blockquote class=3D"gmail_quote"=
style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-lef=
t:1ex"><div dir=3D"ltr">#define RAW(x) x<div><br></div><div><span style=3D"=
font-family:monospace;background-color:rgb(250,250,250);color:rgb(0,0,0)">G=
ENERATE_FUNC</span><span style=3D"font-family:monospace;background-color:rg=
b(250,250,250);color:rgb(102,102,0)">(RAW(</span><span style=3D"font-family=
:monospace;background-color:rgb(250,250,250);color:rgb(0,0,0)">std</span><s=
pan style=3D"font-family:monospace;background-color:rgb(250,250,250);color:=
rgb(102,102,0)">::</span><span style=3D"font-family:monospace;background-co=
lor:rgb(250,250,250);color:rgb(0,0,0)">pair</span><span style=3D"font-famil=
y:monospace;background-color:rgb(250,250,250);color:rgb(102,102,0)"><</s=
pan><span style=3D"font-family:monospace;background-color:rgb(250,250,250);=
color:rgb(0,0,136)">in<wbr>t</span><span style=3D"font-family:monospace;bac=
kground-color:rgb(250,250,250);color:rgb(102,102,0)">,</span><span style=3D=
"font-family:monospace;background-color:rgb(250,250,250);color:rgb(0,0,0)">=
</span><span style=3D"font-family:monospace;background-color:rgb(250,=
250,250);color:rgb(0,0,136)">int</span><span style=3D"font-family:monospace=
;background-color:rgb(250,250,250);color:rgb(102,102,0)">>),</span><span=
style=3D"font-family:monospace;background-color:rgb(250,250,250);color:rgb=
(0,0,0)"> getPair1)</span><span style=3D"font-family:monospace;backgro=
und-color:rgb(250,250,250);color:rgb(102,102,0)">,</span><span style=3D"fon=
t-family:monospace;background-color:rgb(250,250,250);color:rgb(0,0,0)">&nbs=
p;</span><span style=3D"font-family:monospace;background-color:rgb(250,250,=
250);color:rgb(0,0,136)">return</span><span style=3D"font-family:monospace;=
background-color:rgb(250,250,250);color:rgb(0,0,0)"> <wbr>std</span><s=
pan style=3D"font-family:monospace;background-color:rgb(250,250,250);color:=
rgb(102,102,0)">::</span><span style=3D"font-family:monospace;background-co=
lor:rgb(250,250,250);color:rgb(0,0,0)">make_pair</span><span style=3D"font-=
family:monospace;background-color:rgb(250,250,250);color:rgb(102,102,0)">(<=
/span><span style=3D"font-family:monospace;background-color:rgb(250,250,250=
);color:rgb(0,102,102)">1</span><span style=3D"font-family:monospace;backgr=
ound-color:rgb(250,250,250);color:rgb(102,102,0)">,</span><span style=3D"fo=
nt-family:monospace;background-color:rgb(250,250,250);color:rgb(0,0,0)">&nb=
sp;</span><span style=3D"font-family:monospace;background-color:rgb(250,250=
,250);color:rgb(0,102,102)">1</span><span style=3D"font-family:monospace;ba=
ckground-color:rgb(250,250,250)"><font color=3D"#666600">));</font></span><=
br></div><div><br></div><div>The arguments to a macro are identified before=
macro expansion takes place on the arguments. So the above will nest=
out the comma like you want.</div><div><br></div><div>The preprocessor res=
pects parenthesis for nesting arguments.</div><div><br></div><div>From 16.2=
:</div><div><br><div>The sequence of preprocessing tokens bounded by the ou=
tside-most matching parentheses forms the list of</div><div>arguments for t=
he function-like macro. The individual arguments within the list are separa=
ted by comma</div><div>preprocessing tokens, <b>but comma preprocessing tok=
ens between matching inner parentheses do not separate</b></div><div><b>arg=
uments</b>.</div><div><br></div><div><div><b>After the arguments for the in=
vocation of a function-like macro have been identi=EF=AC=81ed, argument sub=
stitution</b></div><div><b>takes place.</b> A parameter in the replacement =
list, unless preceded by a # or ## preprocessing token or</div><div>followe=
d by a ## preprocessing token (see below), is replaced by the corresponding=
argument after all macros</div><div>contained therein have been expanded. =
Before being substituted, each argument=E2=80=99s preprocessing tokens are<=
/div><div>completely macro replaced as if they formed the rest of the prepr=
ocessing =EF=AC=81le; no other preprocessing tokens</div><div>are available=
..</div></div><div><br></div>On Sunday, January 19, 2014 6:28:43 PM UTC+1, V=
ittorio Romeo wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;mar=
gin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr=
"><b>Preprocessor macros</b>, even if potentially <i>unsafe</i>, =
still have place in a lot of C/C++ programs. Using macros is the sometimes =
only way to avoid verbose code repetition, to simulate static reflection or=
to generate code that would be impossible to generate only using templates=
..<div>An issue with macros is that passing arguments is sometimes really co=
unter-intuitive and dangerous. <br><br>Example:</div><div><div style=
=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,187);wor=
d-wrap:break-word"><code><div><span style=3D"color:#800">#define</span><spa=
n style=3D"color:#000"> GENERATE_FUNC</span><span style=3D"color:#660">(</s=
pan><span style=3D"color:#000">mType</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000"> mName</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000"> mBody</span><span style=3D"color:#660">)</sp=
an><span style=3D"color:#000"> mType mName</span><span style=3D"color:#660"=
>(){</span><span style=3D"color:#000"> mBody </span><span style=3D"color:#6=
60">}</span><span style=3D"color:#000"><br><br><br></span><span style=3D"co=
lor:#800">// Ok, generates valid code</span><span style=3D"color:#000"><br>=
GENERATE_FUNC</span><span style=3D"color:#660">(</span><span style=3D"color=
:#008">void</span><span style=3D"color:#660">,</span><span style=3D"color:#=
000"> printHi</span><span style=3D"color:#660">,</span><span style=3D"color=
:#000"> printf</span><span style=3D"color:#660">(</span><span style=3D"colo=
r:#080">"hi"</span><span style=3D"color:#660">);)</span><span style=3D"colo=
r:#000"><br><br><br></span><span style=3D"color:#800">// Ok, generates vali=
d code</span><span style=3D"color:#000"><br>GENERATE_FUNC</span><span style=
=3D"color:#660">(</span><span style=3D"color:#008">void</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> printNumber</span><span=
style=3D"color:#660">,</span><span style=3D"color:#000"> printf</span><spa=
n style=3D"color:#660">(</span><span style=3D"color:#080">"%d"</span><span =
style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#066">5</span><span style=3D"color:#660">);)</span><span style=3D=
"color:#000"><br><br><br></span><span style=3D"color:#800">// The comma in =
"<int, int>" is read as an additional argument - macro expansion fail=
s</span><span style=3D"color:#000"><br>GENERATE_FUNC</span><span style=3D"c=
olor:#660">(</span><span style=3D"color:#000">std</span><span style=3D"colo=
r:#660">::</span><span style=3D"color:#000">pair</span><span style=3D"color=
:#660"><</span><span style=3D"color:#008">int</span><span style=3D"color=
:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#008=
">int</span><span style=3D"color:#660">>,</span><span style=3D"color:#00=
0"> getPair1</span><span style=3D"color:#660">,</span><span style=3D"color:=
#000"> </span><span style=3D"color:#008">return</span><span style=3D"color:=
#000"> std</span><span style=3D"color:#660">::</span><span style=3D"color:#=
000">make_pair</span><span style=3D"color:#660">(</span><span style=3D"colo=
r:#066">1</span><span style=3D"color:#660">,</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#066">1</span><span style=3D"color:#660">);=
)</span><span style=3D"color:#000"><br><br><br></span><span style=3D"color:=
#800">// The comma in "<int, int>" is read correctly, but the generat=
ed code is invalid, as </span><span style=3D"color:#000"><br></span><span s=
tyle=3D"color:#800">// the round parenthesis persist in the return type (lo=
ok below for the expansion)</span><span style=3D"color:#000"><br>GENERATE_F=
UNC</span><span style=3D"color:#660">((</span><span style=3D"color:#000">st=
d</span><span style=3D"color:#660">::</span><span style=3D"color:#000">pair=
</span><span style=3D"color:#660"><</span><span style=3D"color:#008">int=
</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#008">int</span><span style=3D"color:#660">>),</s=
pan><span style=3D"color:#000"> getPair2</span><span style=3D"color:#660">,=
</span><span style=3D"color:#000"> </span><span style=3D"color:#008">return=
</span><span style=3D"color:#000"> std</span><span style=3D"color:#660">::<=
/span><span style=3D"color:#000">make_pair</span><span style=3D"color:#660"=
>(</span><span style=3D"color:#066">1</span><span style=3D"color:#660">,</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#066">1</span><=
span style=3D"color:#660">);)</span><span style=3D"color:#000"><br></span><=
span style=3D"color:#800">/*<br> (std::pair<int, int>) g=
etPair2() { return std::make_pair(1, 1); }<br>*/</span></div></code></div><=
div><br></div></div><div>There are possible solutions to this issue:</div>1=
.. Create a typedef for `std::pair<int, int>` - this solution is speci=
fic to this case, and may not always be applicable. Additionally, it requir=
es the coder to define a new typedef,<div>2. Create multiple macros (for ex=
ample, GENERATE_FUNC_START and GENERATE_FUNC_END), and let the user write t=
he code in-between - this solution is ugly and error prone. Also, it scales=
poorly, as k "body" arguments would require k+1 macro definitions.</div><d=
iv><br></div><div>These solutions, however, can be defined <i>hacks. </i>Th=
e issue is that there is no way to pass a "raw" argument to the preprocesso=
r. </div><div><br></div><div>Here's what I propose:</div><div><b>Simil=
arly to C++11 raw strings, have a new syntax that allows the user to pass "=
raw arguments" to preprocessor macros.</b></div><div><br></div><div>Example=
:</div><div><div style=3D"background-color:rgb(250,250,250);border:1px soli=
d rgb(187,187,187);word-wrap:break-word"><code><div><font color=3D"#000000"=
><span style=3D"color:#000">GENERATE_FUNC</span><span style=3D"color:#660">=
(</span><span style=3D"color:#000">__R</span><span style=3D"color:#660">(</=
span><span style=3D"color:#000">std</span><span style=3D"color:#660">::</sp=
an><span style=3D"color:#000">pair</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#008">in<wbr>t</span><span style=3D"color:#660">,<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">int</sp=
an><span style=3D"color:#660">>),</span><span style=3D"color:#000"> __R<=
/span><span style=3D"color:#660">(</span><span style=3D"color:#000">getPair=
Raw</span><span style=3D"color:#660">),</span><span style=3D"color:#000"> _=
_R</span><span style=3D"color:#660">(</span><span style=3D"color:#008">retu=
rn</span><span style=3D"color:#000"> std</span><span style=3D"color:#660">:=
:</span><span style=3D"color:#000">make_pair</span><span style=3D"color:#66=
0">(</span><span style=3D"color:#066">1</span><span style=3D"color:#660">,<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#066">1</span=
><span style=3D"color:#660">))</span><span style=3D"color:#000"><br></span>=
</font></div></code></div><br>Specification:</div><div><div style=3D"backgr=
ound-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:bre=
ak-word"><code><div><font color=3D"#660066"><span style=3D"color:#000"><=
__R > </span><span style=3D"color:#008"><prefix></span><span styl=
e=3D"color:#000"> <(> <...> <)> </span><span style=3D"col=
or:#008"><suffix></span><span style=3D"color:#000"> </span></font></d=
iv></code></div><br>Prefix/suffix example:</div><div><div style=3D"backgrou=
nd-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:break=
-word"><code><div><span style=3D"color:#000">GENERATE_FUNC</span><span styl=
e=3D"color:#660">(</span><span style=3D"color:#000">__R</span><span style=
=3D"color:#660">***(</span><span style=3D"color:#606">ReturnTyp<wbr>e</span=
><span style=3D"color:#660">(</span><span style=3D"color:#008">int</span><s=
pan style=3D"color:#660">*))***,</span><span style=3D"color:#000"> __R</spa=
n><span style=3D"color:#660">(</span><span style=3D"color:#000">getIntPtr</=
span><span style=3D"color:#660">),</span><span style=3D"color:#000"> __R</s=
pan><span style=3D"color:#660">(</span><span style=3D"color:#008">return</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">&</sp=
an><font color=3D"#006666"><span style=3D"color:#000">someInt</span><span s=
tyle=3D"color:#660">;))</span><span style=3D"color:#000"><br></span></font>=
</div></code></div><br></div><div>Unit test before example:</div><div><div =
style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,187=
);word-wrap:break-word"><code><div><font color=3D"#660066"><span style=3D"c=
olor:#000">UNIT_TEST_START</span><span style=3D"color:#660">()</span><span =
style=3D"color:#000"><br></span></font><span style=3D"color:#000"> &n=
bsp; EXPECT</span><span style=3D"color:#660">(</span><span style=3D"c=
olor:#000">some predicate</span><span style=3D"color:#660">);</span><span s=
tyle=3D"color:#000"><br> </span><span style=3D"color:#66=
0">...</span><span style=3D"color:#000"> <br></span><font color=3D"#660066"=
><span style=3D"color:#000">UNIT_TEST_END</span><span style=3D"color:#660">=
()</span></font></div></code></div><br></div><div>Unit test after example:<=
/div><div><div style=3D"background-color:rgb(250,250,250);border:1px solid =
rgb(187,187,187);word-wrap:break-word"><code><div><font color=3D"#660066"><=
span style=3D"color:#000">UNIT_TEST</span><span style=3D"color:#660">(</spa=
n><span style=3D"color:#000">__R</span><span style=3D"color:#660">(</span><=
span style=3D"color:#000"><br> EXPECT</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">some predicate</span><sp=
an style=3D"color:#660">);</span><span style=3D"color:#000"><br> &nbs=
p; </span><span style=3D"color:#660">...</span><span style=3D"color:#=
000"> <br></span><span style=3D"color:#660">))</span></font></div></code></=
div><br>This "raw syntax" would also fix the "comma problem", that forced u=
sers to define a "COMMA" macro for years:</div><div><div style=3D"backgroun=
d-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:break-=
word"><code><div><font color=3D"#660066"><span style=3D"color:#000">__R</sp=
an><span style=3D"color:#660">(,)</span></font></div></code></div><br><b>Wh=
at do you think?</b></div></div></blockquote></div></div></blockquote></div=
></div></blockquote></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 />
------=_Part_550_15354894.1390179978103--
.
Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Sun, 19 Jan 2014 18:49:25 -0800 (PST)
Raw View
------=_Part_1863_8535418.1390186165826
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
No it won't, __VA_ARGS__ leaves the commas in.
-Andrew.
On Monday, January 20, 2014 2:06:18 AM UTC+1, jgot...@gmail.com wrote:
>
> I think this is still slightly wrong. Won't it eat the comma, so that=20
> RAW(std::pair<int, int>)
> becomes
> std::pair<int int> //no comma!
>
> Joe Gottman
>
> On Sunday, January 19, 2014 5:15:46 PM UTC-5, Andrew Tomazos wrote:
>>
>> Actually sorry, I am slightly wrong about that solution. The argument t=
o=20
>> RAW will be parsed in turn as two arguments and not one. It should be:
>>
>> #define RAW(...) __VA_ARGS__
>>
>> This will work I think.
>>
>> On Sunday, January 19, 2014 10:11:35 PM UTC+1, Andrew Tomazos wrote:
>>>
>>> #define RAW(x) x
>>>
>>> GENERATE_FUNC(RAW(std::pair<int, int>), getPair1), return std::make_pai=
r
>>> (1, 1));
>>>
>>> The arguments to a macro are identified before macro expansion takes=20
>>> place on the arguments. So the above will nest out the comma like you =
want.
>>>
>>> The preprocessor respects parenthesis for nesting arguments.
>>>
>>> From 16.2:
>>>
>>> The sequence of preprocessing tokens bounded by the outside-most=20
>>> matching parentheses forms the list of
>>> arguments for the function-like macro. The individual arguments within=
=20
>>> the list are separated by comma
>>> preprocessing tokens, *but comma preprocessing tokens between matching=
=20
>>> inner parentheses do not separate*
>>> *arguments*.
>>>
>>> *After the arguments for the invocation of a function-like macro have=
=20
>>> been identi=EF=AC=81ed, argument substitution*
>>> *takes place.* A parameter in the replacement list, unless preceded by=
=20
>>> a # or ## preprocessing token or
>>> followed by a ## preprocessing token (see below), is replaced by the=20
>>> corresponding argument after all macros
>>> contained therein have been expanded. Before being substituted, each=20
>>> argument=E2=80=99s preprocessing tokens are
>>> completely macro replaced as if they formed the rest of the=20
>>> preprocessing =EF=AC=81le; no other preprocessing tokens
>>> are available.
>>>
>>> On Sunday, January 19, 2014 6:28:43 PM UTC+1, Vittorio Romeo wrote:
>>>>
>>>> *Preprocessor macros*, even if potentially *unsafe*, still have place=
=20
>>>> in a lot of C/C++ programs. Using macros is the sometimes only way to =
avoid=20
>>>> verbose code repetition, to simulate static reflection or to generate =
code=20
>>>> that would be impossible to generate only using templates.
>>>> An issue with macros is that passing arguments is sometimes really=20
>>>> counter-intuitive and dangerous.=20
>>>>
>>>> Example:
>>>> #define GENERATE_FUNC(mType, mName, mBody) mType mName(){ mBody }
>>>>
>>>>
>>>> // Ok, generates valid code
>>>> GENERATE_FUNC(void, printHi, printf("hi");)
>>>>
>>>>
>>>> // Ok, generates valid code
>>>> GENERATE_FUNC(void, printNumber, printf("%d", 5);)
>>>>
>>>>
>>>> // The comma in "<int, int>" is read as an additional argument - macro=
=20
>>>> expansion fails
>>>> GENERATE_FUNC(std::pair<int, int>, getPair1, return std::make_pair(1, =
1
>>>> );)
>>>>
>>>>
>>>> // The comma in "<int, int>" is read correctly, but the generated code=
=20
>>>> is invalid, as=20
>>>> // the round parenthesis persist in the return type (look below for th=
e=20
>>>> expansion)
>>>> GENERATE_FUNC((std::pair<int, int>), getPair2, return std::make_pair(1=
,=20
>>>> 1);)
>>>> /*
>>>> (std::pair<int, int>) getPair2() { return std::make_pair(1, 1); }
>>>> */
>>>>
>>>> There are possible solutions to this issue:
>>>> 1. Create a typedef for `std::pair<int, int>` - this solution is=20
>>>> specific to this case, and may not always be applicable. Additionally,=
it=20
>>>> requires the coder to define a new typedef,
>>>> 2. Create multiple macros (for example, GENERATE_FUNC_START and=20
>>>> GENERATE_FUNC_END), and let the user write the code in-between - this=
=20
>>>> solution is ugly and error prone. Also, it scales poorly, as k "body"=
=20
>>>> arguments would require k+1 macro definitions.
>>>>
>>>> These solutions, however, can be defined *hacks. *The issue is that=20
>>>> there is no way to pass a "raw" argument to the preprocessor.=20
>>>>
>>>> Here's what I propose:
>>>> *Similarly to C++11 raw strings, have a new syntax that allows the use=
r=20
>>>> to pass "raw arguments" to preprocessor macros.*
>>>>
>>>> Example:
>>>> GENERATE_FUNC(__R(std::pair<int, int>), __R(getPairRaw), __R(return st=
d
>>>> ::make_pair(1, 1))
>>>>
>>>> Specification:
>>>> < __R > <prefix> <(> <...> <)> <suffix>=20
>>>>
>>>> Prefix/suffix example:
>>>> GENERATE_FUNC(__R***(ReturnType(int*))***, __R(getIntPtr), __R(return =
&
>>>> someInt;))
>>>>
>>>> Unit test before example:
>>>> UNIT_TEST_START()
>>>> EXPECT(some predicate);
>>>> ...=20
>>>> UNIT_TEST_END()
>>>>
>>>> Unit test after example:
>>>> UNIT_TEST(__R(
>>>> EXPECT(some predicate);
>>>> ...=20
>>>> ))
>>>>
>>>> This "raw syntax" would also fix the "comma problem", that forced user=
s=20
>>>> to define a "COMMA" macro for years:
>>>> __R(,)
>>>>
>>>> *What do you think?*
>>>>
>>>
--=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/.
------=_Part_1863_8535418.1390186165826
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">No it won't, __VA_ARGS__ leaves the commas in.<br> -=
Andrew.<br><br>On Monday, January 20, 2014 2:06:18 AM UTC+1, jgot...@gmail.=
com 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">I t=
hink this is still slightly wrong. Won't it eat the comma, so that <d=
iv 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><div><span=
style=3D"color:#000">RAW</span><span style=3D"color:#660">(</span><span st=
yle=3D"color:#000">std</span><span style=3D"color:#660">::</span><span styl=
e=3D"color:#000">pair</span><span style=3D"color:#660"><</span><span sty=
le=3D"color:#008">int</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">int</span><span style=3D=
"color:#660">>)</span><span style=3D"color:#000"><br></span></div></code=
></div>becomes<br><div style=3D"background-color:rgb(250,250,250);border-co=
lor:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-wo=
rd"><code><div><span style=3D"color:#000">std</span><span style=3D"color:#6=
60">::</span><span style=3D"color:#000">pair</span><span style=3D"color:#66=
0"><</span><span style=3D"color:#008">int</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#008">int</span><span style=3D"color:#660">=
></span><span style=3D"color:#000"> </span><span style=3D"color:#800">//=
no comma!</span><span style=3D"color:#000"><br></span></div></code></div><b=
r>Joe Gottman<br><br>On Sunday, January 19, 2014 5:15:46 PM UTC-5, Andrew T=
omazos wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-lef=
t:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Actua=
lly sorry, I am slightly wrong about that solution. The argument to R=
AW will be parsed in turn as two arguments and not one. It should be:=
<div><br></div><div> #define RAW(...) __VA_ARGS__<br><br>This =
will work I think.</div><div><br></div><div>On Sunday, January 19, 2014 10:=
11:35 PM UTC+1, Andrew Tomazos wrote:<blockquote class=3D"gmail_quote" styl=
e=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex=
"><div dir=3D"ltr">#define RAW(x) x<div><br></div><div><span style=3D"font-=
family:monospace;background-color:rgb(250,250,250);color:rgb(0,0,0)">GENERA=
TE_FUNC</span><span style=3D"font-family:monospace;background-color:rgb(250=
,250,250);color:rgb(102,102,0)">(RAW(</span><span style=3D"font-family:mono=
space;background-color:rgb(250,250,250);color:rgb(0,0,0)">std</span><span s=
tyle=3D"font-family:monospace;background-color:rgb(250,250,250);color:rgb(1=
02,102,0)">::</span><span style=3D"font-family:monospace;background-color:r=
gb(250,250,250);color:rgb(0,0,0)">pair</span><span style=3D"font-family:mon=
ospace;background-color:rgb(250,250,250);color:rgb(102,102,0)"><</span><=
span style=3D"font-family:monospace;background-color:rgb(250,250,250);color=
:rgb(0,0,136)">in<wbr>t</span><span style=3D"font-family:monospace;backgrou=
nd-color:rgb(250,250,250);color:rgb(102,102,0)">,</span><span style=3D"font=
-family:monospace;background-color:rgb(250,250,250);color:rgb(0,0,0)"> =
;</span><span style=3D"font-family:monospace;background-color:rgb(250,250,2=
50);color:rgb(0,0,136)">int</span><span style=3D"font-family:monospace;back=
ground-color:rgb(250,250,250);color:rgb(102,102,0)">>),</span><span styl=
e=3D"font-family:monospace;background-color:rgb(250,250,250);color:rgb(0,0,=
0)"> getPair1)</span><span style=3D"font-family:monospace;background-c=
olor:rgb(250,250,250);color:rgb(102,102,0)">,</span><span style=3D"font-fam=
ily:monospace;background-color:rgb(250,250,250);color:rgb(0,0,0)"> </s=
pan><span style=3D"font-family:monospace;background-color:rgb(250,250,250);=
color:rgb(0,0,136)">return</span><span style=3D"font-family:monospace;backg=
round-color:rgb(250,250,250);color:rgb(0,0,0)"> <wbr>std</span><span s=
tyle=3D"font-family:monospace;background-color:rgb(250,250,250);color:rgb(1=
02,102,0)">::</span><span style=3D"font-family:monospace;background-color:r=
gb(250,250,250);color:rgb(0,0,0)">make_pair</span><span style=3D"font-famil=
y:monospace;background-color:rgb(250,250,250);color:rgb(102,102,0)">(</span=
><span style=3D"font-family:monospace;background-color:rgb(250,250,250);col=
or:rgb(0,102,102)">1</span><span style=3D"font-family:monospace;background-=
color:rgb(250,250,250);color:rgb(102,102,0)">,</span><span style=3D"font-fa=
mily:monospace;background-color:rgb(250,250,250);color:rgb(0,0,0)"> </=
span><span style=3D"font-family:monospace;background-color:rgb(250,250,250)=
;color:rgb(0,102,102)">1</span><span style=3D"font-family:monospace;backgro=
und-color:rgb(250,250,250)"><font color=3D"#666600">));</font></span><br></=
div><div><br></div><div>The arguments to a macro are identified before macr=
o expansion takes place on the arguments. So the above will nest out =
the comma like you want.</div><div><br></div><div>The preprocessor respects=
parenthesis for nesting arguments.</div><div><br></div><div>From 16.2:</di=
v><div><br><div>The sequence of preprocessing tokens bounded by the outside=
-most matching parentheses forms the list of</div><div>arguments for the fu=
nction-like macro. The individual arguments within the list are separated b=
y comma</div><div>preprocessing tokens, <b>but comma preprocessing tokens b=
etween matching inner parentheses do not separate</b></div><div><b>argument=
s</b>.</div><div><br></div><div><div><b>After the arguments for the invocat=
ion of a function-like macro have been identi=EF=AC=81ed, argument substitu=
tion</b></div><div><b>takes place.</b> A parameter in the replacement list,=
unless preceded by a # or ## preprocessing token or</div><div>followed by =
a ## preprocessing token (see below), is replaced by the corresponding argu=
ment after all macros</div><div>contained therein have been expanded. Befor=
e being substituted, each argument=E2=80=99s preprocessing tokens are</div>=
<div>completely macro replaced as if they formed the rest of the preprocess=
ing =EF=AC=81le; no other preprocessing tokens</div><div>are available.</di=
v></div><div><br></div>On Sunday, January 19, 2014 6:28:43 PM UTC+1, Vittor=
io Romeo wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-l=
eft:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><b>=
Preprocessor macros</b>, even if potentially <i>unsafe</i>, still=
have place in a lot of C/C++ programs. Using macros is the sometimes only =
way to avoid verbose code repetition, to simulate static reflection or to g=
enerate code that would be impossible to generate only using templates.<div=
>An issue with macros is that passing arguments is sometimes really counter=
-intuitive and dangerous. <br><br>Example:</div><div><div style=3D"bac=
kground-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:=
break-word"><code><div><span style=3D"color:#800">#define</span><span style=
=3D"color:#000"> GENERATE_FUNC</span><span style=3D"color:#660">(</span><sp=
an style=3D"color:#000">mType</span><span style=3D"color:#660">,</span><spa=
n style=3D"color:#000"> mName</span><span style=3D"color:#660">,</span><spa=
n style=3D"color:#000"> mBody</span><span style=3D"color:#660">)</span><spa=
n style=3D"color:#000"> mType mName</span><span style=3D"color:#660">(){</s=
pan><span style=3D"color:#000"> mBody </span><span style=3D"color:#660">}</=
span><span style=3D"color:#000"><br><br><br></span><span style=3D"color:#80=
0">// Ok, generates valid code</span><span style=3D"color:#000"><br>GENERAT=
E_FUNC</span><span style=3D"color:#660">(</span><span style=3D"color:#008">=
void</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> p=
rintHi</span><span style=3D"color:#660">,</span><span style=3D"color:#000">=
printf</span><span style=3D"color:#660">(</span><span style=3D"color:#080"=
>"hi"</span><span style=3D"color:#660">);)</span><span style=3D"color:#000"=
><br><br><br></span><span style=3D"color:#800">// Ok, generates valid code<=
/span><span style=3D"color:#000"><br>GENERATE_FUNC</span><span style=3D"col=
or:#660">(</span><span style=3D"color:#008">void</span><span style=3D"color=
:#660">,</span><span style=3D"color:#000"> printNumber</span><span style=3D=
"color:#660">,</span><span style=3D"color:#000"> printf</span><span style=
=3D"color:#660">(</span><span style=3D"color:#080">"%d"</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#066">5</span><span style=3D"color:#660">);)</span><span style=3D"colo=
r:#000"><br><br><br></span><span style=3D"color:#800">// The comma in "<=
int, int>" is read as an additional argument - macro expansion fails</sp=
an><span style=3D"color:#000"><br>GENERATE_FUNC</span><span style=3D"color:=
#660">(</span><span style=3D"color:#000">std</span><span style=3D"color:#66=
0">::</span><span style=3D"color:#000">pair</span><span style=3D"color:#660=
"><</span><span style=3D"color:#008">int</span><span style=3D"color:#660=
">,</span><span style=3D"color:#000"> </span><span style=3D"color:#008">int=
</span><span style=3D"color:#660">>,</span><span style=3D"color:#000"> g=
etPair1</span><span style=3D"color:#660">,</span><span style=3D"color:#000"=
> </span><span style=3D"color:#008">return</span><span style=3D"color:#000"=
> std</span><span style=3D"color:#660">::</span><span style=3D"color:#000">=
make_pair</span><span style=3D"color:#660">(</span><span style=3D"color:#06=
6">1</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#066">1</span><span style=3D"color:#660">);)</sp=
an><span style=3D"color:#000"><br><br><br></span><span style=3D"color:#800"=
>// The comma in "<int, int>" is read correctly, but the generated co=
de is invalid, as </span><span style=3D"color:#000"><br></span><span style=
=3D"color:#800">// the round parenthesis persist in the return type (look b=
elow for the expansion)</span><span style=3D"color:#000"><br>GENERATE_FUNC<=
/span><span style=3D"color:#660">((</span><span style=3D"color:#000">std</s=
pan><span style=3D"color:#660">::</span><span style=3D"color:#000">pair</sp=
an><span style=3D"color:#660"><</span><span style=3D"color:#008">int</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#008">int</span><span style=3D"color:#660">>),</span>=
<span style=3D"color:#000"> getPair2</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#008">return</sp=
an><span style=3D"color:#000"> std</span><span style=3D"color:#660">::</spa=
n><span style=3D"color:#000">make_pair</span><span style=3D"color:#660">(</=
span><span style=3D"color:#066">1</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#066">1</span><span=
style=3D"color:#660">);)</span><span style=3D"color:#000"><br></span><span=
style=3D"color:#800">/*<br> (std::pair<int, int>) getPa=
ir2() { return std::make_pair(1, 1); }<br>*/</span></div></code></div><div>=
<br></div></div><div>There are possible solutions to this issue:</div>1. Cr=
eate a typedef for `std::pair<int, int>` - this solution is specific =
to this case, and may not always be applicable. Additionally, it requires t=
he coder to define a new typedef,<div>2. Create multiple macros (for exampl=
e, GENERATE_FUNC_START and GENERATE_FUNC_END), and let the user write the c=
ode in-between - this solution is ugly and error prone. Also, it scales poo=
rly, as k "body" arguments would require k+1 macro definitions.</div><div><=
br></div><div>These solutions, however, can be defined <i>hacks. </i>The is=
sue is that there is no way to pass a "raw" argument to the preprocessor.&n=
bsp;</div><div><br></div><div>Here's what I propose:</div><div><b>Similarly=
to C++11 raw strings, have a new syntax that allows the user to pass "raw =
arguments" to preprocessor macros.</b></div><div><br></div><div>Example:</d=
iv><div><div style=3D"background-color:rgb(250,250,250);border:1px solid rg=
b(187,187,187);word-wrap:break-word"><code><div><font color=3D"#000000"><sp=
an style=3D"color:#000">GENERATE_FUNC</span><span style=3D"color:#660">(</s=
pan><span style=3D"color:#000">__R</span><span style=3D"color:#660">(</span=
><span style=3D"color:#000">std</span><span style=3D"color:#660">::</span><=
span style=3D"color:#000">pair</span><span style=3D"color:#660"><</span>=
<span style=3D"color:#008">in<wbr>t</span><span style=3D"color:#660">,</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#008">int</span><=
span style=3D"color:#660">>),</span><span style=3D"color:#000"> __R</spa=
n><span style=3D"color:#660">(</span><span style=3D"color:#000">getPairRaw<=
/span><span style=3D"color:#660">),</span><span style=3D"color:#000"> __R</=
span><span style=3D"color:#660">(</span><span style=3D"color:#008">return</=
span><span style=3D"color:#000"> std</span><span style=3D"color:#660">::</s=
pan><span style=3D"color:#000">make_pair</span><span style=3D"color:#660">(=
</span><span style=3D"color:#066">1</span><span style=3D"color:#660">,</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#066">1</span><sp=
an style=3D"color:#660">))</span><span style=3D"color:#000"><br></span></fo=
nt></div></code></div><br>Specification:</div><div><div style=3D"background=
-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:break-w=
ord"><code><div><font color=3D"#660066"><span style=3D"color:#000">< __R=
> </span><span style=3D"color:#008"><prefix></span><span style=3D=
"color:#000"> <(> <...> <)> </span><span style=3D"color:#=
008"><suffix></span><span style=3D"color:#000"> </span></font></div><=
/code></div><br>Prefix/suffix example:</div><div><div style=3D"background-c=
olor:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:break-wor=
d"><code><div><span style=3D"color:#000">GENERATE_FUNC</span><span style=3D=
"color:#660">(</span><span style=3D"color:#000">__R</span><span style=3D"co=
lor:#660">***(</span><span style=3D"color:#606">ReturnTyp<wbr>e</span><span=
style=3D"color:#660">(</span><span style=3D"color:#008">int</span><span st=
yle=3D"color:#660">*))***,</span><span style=3D"color:#000"> __R</span><spa=
n style=3D"color:#660">(</span><span style=3D"color:#000">getIntPtr</span><=
span style=3D"color:#660">),</span><span style=3D"color:#000"> __R</span><s=
pan style=3D"color:#660">(</span><span style=3D"color:#008">return</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">&</span><fo=
nt color=3D"#006666"><span style=3D"color:#000">someInt</span><span style=
=3D"color:#660">;))</span><span style=3D"color:#000"><br></span></font></di=
v></code></div><br></div><div>Unit test before example:</div><div><div styl=
e=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,187,187);wo=
rd-wrap:break-word"><code><div><font color=3D"#660066"><span style=3D"color=
:#000">UNIT_TEST_START</span><span style=3D"color:#660">()</span><span styl=
e=3D"color:#000"><br></span></font><span style=3D"color:#000"> =
EXPECT</span><span style=3D"color:#660">(</span><span style=3D"color=
:#000">some predicate</span><span style=3D"color:#660">);</span><span style=
=3D"color:#000"><br> </span><span style=3D"color:#660">.=
...</span><span style=3D"color:#000"> <br></span><font color=3D"#660066"><sp=
an style=3D"color:#000">UNIT_TEST_END</span><span style=3D"color:#660">()</=
span></font></div></code></div><br></div><div>Unit test after example:</div=
><div><div style=3D"background-color:rgb(250,250,250);border:1px solid rgb(=
187,187,187);word-wrap:break-word"><code><div><font color=3D"#660066"><span=
style=3D"color:#000">UNIT_TEST</span><span style=3D"color:#660">(</span><s=
pan style=3D"color:#000">__R</span><span style=3D"color:#660">(</span><span=
style=3D"color:#000"><br> EXPECT</span><span style=3D"c=
olor:#660">(</span><span style=3D"color:#000">some predicate</span><span st=
yle=3D"color:#660">);</span><span style=3D"color:#000"><br> &n=
bsp;</span><span style=3D"color:#660">...</span><span style=3D"color:#000">=
<br></span><span style=3D"color:#660">))</span></font></div></code></div><=
br>This "raw syntax" would also fix the "comma problem", that forced users =
to define a "COMMA" macro for years:</div><div><div style=3D"background-col=
or:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:break-word"=
><code><div><font color=3D"#660066"><span style=3D"color:#000">__R</span><s=
pan style=3D"color:#660">(,)</span></font></div></code></div><br><b>What do=
you think?</b></div></div></blockquote></div></div></blockquote></div></di=
v></blockquote></div></blockquote></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 />
------=_Part_1863_8535418.1390186165826--
.
Author: Vittorio Romeo <vittorio.romeo.vee@gmail.com>
Date: Mon, 20 Jan 2014 00:34:40 -0800 (PST)
Raw View
------=_Part_1_31624070.1390206880217
Content-Type: text/plain; charset=UTF-8
I'm testing out the __VA_ARGS__ solution. Results are promising so far.
http://ideone.com/q8p6tE
http://ideone.com/S7Cy9Q
Maybe this issue is "solved"?
--
---
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_1_31624070.1390206880217
Content-Type: text/html; charset=UTF-8
<div dir="ltr">I'm testing out the __VA_ARGS__ solution. Results are promising so far.<div><br></div><div>http://ideone.com/q8p6tE<br></div><div>http://ideone.com/S7Cy9Q<br></div><div><br></div><div>Maybe this issue is "solved"?</div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email 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="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />
------=_Part_1_31624070.1390206880217--
.
Author: Vittorio Romeo <vittorio.romeo.vee@gmail.com>
Date: Mon, 20 Jan 2014 00:53:04 -0800 (PST)
Raw View
------=_Part_1796_16970866.1390207984103
Content-Type: text/plain; charset=UTF-8
http://ideone.com/B5hVDS
This example shows un-intuitive behavior.
The "raw argument" is actually passed as multiple arguments, and does not
expand correctly.
I would expect the program to print "1, 2, 3" or "1,2,3" - instead, it
fails to compile.
--
---
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_1796_16970866.1390207984103
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">http://ideone.com/B5hVDS<br><br>This example shows un-intu=
itive behavior.<div>The "raw argument" is actually passed as multiple argum=
ents, and does not expand correctly.</div><div><br></div><div>I would expec=
t the program to print "1, 2, 3" or "1,2,3" - instead, it fails to compile.=
</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 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 />
------=_Part_1796_16970866.1390207984103--
.
Author: Roland Bock <rbock@eudoxos.de>
Date: Mon, 20 Jan 2014 10:00:36 +0100
Raw View
On 2014-01-20 09:53, Vittorio Romeo wrote:
> http://ideone.com/B5hVDS
>
> This example shows un-intuitive behavior.
> The "raw argument" is actually passed as multiple arguments, and does
> not expand correctly.
>
> I would expect the program to print "1, 2, 3" or "1,2,3" - instead, it
> fails to compile.
>
Did not check the other examples, but how about this:
#define RAW(...) (__VA_ARGS__)
http://ideone.com/DXXOXP (works as expected)
--
---
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/.
.
Author: Vittorio Romeo <vittorio.romeo.vee@gmail.com>
Date: Mon, 20 Jan 2014 02:49:08 -0800 (PST)
Raw View
------=_Part_78_6611027.1390214948436
Content-Type: text/plain; charset=UTF-8
This is not what I expect, since it also prints the parenthesis.
The solution would be having a "variadic stringify function"
#define SSVPP_IMPL_STRINGIFYWITHCOMMAS(mIdx, mData, mArg) SSVPP_STRINGIFY(mArg)SSVPP_IF(mIdx, ", ", SSVPP_EMPTY())
#define SSVPP_STRINGIFYWITHCOMMAS(...) SSVPP_FOREACH(SSVPP_IMPL_STRINGIFYWITHCOMMAS, SSVPP_EMPTY(), __VA_ARGS__)
However, it needs to be explicitly called, and the "raw argument"
consistency fails here.
On Monday, 20 January 2014 10:00:36 UTC+1, Roland Bock wrote:
>
> On 2014-01-20 09:53, Vittorio Romeo wrote:
> > http://ideone.com/B5hVDS
> >
> > This example shows un-intuitive behavior.
> > The "raw argument" is actually passed as multiple arguments, and does
> > not expand correctly.
> >
> > I would expect the program to print "1, 2, 3" or "1,2,3" - instead, it
> > fails to compile.
> >
> Did not check the other examples, but how about this:
>
> #define RAW(...) (__VA_ARGS__)
>
>
> http://ideone.com/DXXOXP (works as expected)
>
--
---
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_78_6611027.1390214948436
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">This is not what I expect, since it also prints the parent=
hesis. <br>The solution would be having a "variadic stringify function=
"<div><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 2=
50); border: 1px solid rgb(187, 187, 187); word-wrap: break-word;"><code cl=
ass=3D"prettyprint"><div class=3D"subprettyprint"><pre><span style=3D" colo=
r:#ef2672;"><span style=3D"color: #800;" class=3D"styled-by-prettify">#defi=
ne</span></span><span style=3D" color:#3e3d32;"><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span></span><span style=3D" color:#ef2672=
;"><span style=3D"color: #000;" class=3D"styled-by-prettify">SSVPP_IMPL_STR=
INGIFYWITHCOMMAS</span></span><span style=3D" color:#e6e5e2;"><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span></span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">mIdx</span><span style=3D" c=
olor:#e6e5e2;"><span style=3D"color: #660;" class=3D"styled-by-prettify">,<=
/span></span><span style=3D" color:#3e3d32;"><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span></span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">mData</span><span style=3D" color:#e6e5e2;"><span=
style=3D"color: #660;" class=3D"styled-by-prettify">,</span></span><span s=
tyle=3D" color:#3e3d32;"><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span></span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">mArg</span><span style=3D" color:#e6e5e2;"><span style=3D"color: #660=
;" class=3D"styled-by-prettify">)</span></span><span style=3D" color:#3e3d3=
2;"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n></span><span style=3D" color:#ef2672;"><span style=3D"color: #000;" class=
=3D"styled-by-prettify">SSVPP_STRINGIFY</span></span><span style=3D" color:=
#e6e5e2;"><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
></span><span style=3D"color: #000;" class=3D"styled-by-prettify">mArg</spa=
n><span style=3D" color:#e6e5e2;"><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">)</span></span><span style=3D" color:#ef2672;"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">SSVPP_IF</span></span><span =
style=3D" color:#e6e5e2;"><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(</span></span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">mIdx</span><span style=3D" color:#e6e5e2;"><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">,</span></span><span style=3D" color:#3e3d=
32;"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span></sp=
an><span style=3D" color:#e6db74;"><span style=3D"color: #080;" class=3D"st=
yled-by-prettify">",</span></span><span style=3D" color:#3e3d32;"><span sty=
le=3D"color: #080;" class=3D"styled-by-prettify"> </span></span><span style=
=3D" color:#e6db74;"><span style=3D"color: #080;" class=3D"styled-by-pretti=
fy">"</span></span><span style=3D" color:#e6e5e2;"><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">,</span></span><span style=3D" color:#3e3=
d32;"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span></s=
pan><span style=3D" color:#ef2672;"><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">SSVPP_EMPTY</span></span><span style=3D" color:#e6e5e2;"=
><span style=3D"color: #660;" class=3D"styled-by-prettify">())</span></span=
></pre><pre><span style=3D" color:#ef2672;"><span style=3D"color: #800;" cl=
ass=3D"styled-by-prettify">#define</span></span><span style=3D" color:#3e3d=
32;"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span></sp=
an><span style=3D" color:#ef2672;"><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">SSVPP_STRINGIFYWITHCOMMAS</span></span><span style=3D" co=
lor:#e6e5e2;"><span style=3D"color: #660;" class=3D"styled-by-prettify">(..=
..)</span></span><span style=3D" color:#3e3d32;"><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> &=
nbsp; </span></span><span style=3D" color:#ef267=
2;"><span style=3D"color: #000;" class=3D"styled-by-prettify">SSVPP_FOREACH=
</span></span><span style=3D" color:#e6e5e2;"><span style=3D"color: #660;" =
class=3D"styled-by-prettify">(</span></span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">SSVPP_IMPL_STRINGIFYWITHCOMMAS</span><span style=
=3D" color:#e6e5e2;"><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">,</span></span><span style=3D" color:#3e3d32;"><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span></span><span style=3D" color:#ef2=
672;"><span style=3D"color: #000;" class=3D"styled-by-prettify">SSVPP_EMPTY=
</span></span><span style=3D" color:#e6e5e2;"><span style=3D"color: #660;" =
class=3D"styled-by-prettify">(),</span></span><span style=3D" color:#3e3d32=
;"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span></span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">__VA_ARGS__</spa=
n><span style=3D" color:#e6e5e2;"><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">)</span></span></pre></div></code></div><br>However, it ne=
eds to be explicitly called, and the "raw argument" consistency fails here.=
<br><br>On Monday, 20 January 2014 10:00:36 UTC+1, Roland Bock wrote:<bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;">On 2014-01-20 09:53, Vittorio Romeo=
wrote:
<br>> <a href=3D"http://ideone.com/B5hVDS" target=3D"_blank" onmousedown=
=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fideone.com%2FB5=
hVDS\46sa\75D\46sntz\0751\46usg\75AFQjCNFN00duigtqjYQCPYDVTUIs2QmR1w';retur=
n true;" onclick=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F%2=
Fideone.com%2FB5hVDS\46sa\75D\46sntz\0751\46usg\75AFQjCNFN00duigtqjYQCPYDVT=
UIs2QmR1w';return true;">http://ideone.com/B5hVDS</a>
<br>>
<br>> This example shows un-intuitive behavior.
<br>> The "raw argument" is actually passed as multiple arguments, and d=
oes
<br>> not expand correctly.
<br>>
<br>> I would expect the program to print "1, 2, 3" or "1,2,3" - instead=
, it
<br>> fails to compile.
<br>>
<br>Did not check the other examples, but how about this:
<br>
<br>#define RAW(...) (__VA_ARGS__)
<br>
<br>
<br><a href=3D"http://ideone.com/DXXOXP" target=3D"_blank" onmousedown=3D"t=
his.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fideone.com%2FDXXOXP\=
46sa\75D\46sntz\0751\46usg\75AFQjCNE0QEFIl6Yaqmdo5g6xSgGW64vK2Q';return tru=
e;" onclick=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fideo=
ne.com%2FDXXOXP\46sa\75D\46sntz\0751\46usg\75AFQjCNE0QEFIl6Yaqmdo5g6xSgGW64=
vK2Q';return true;">http://ideone.com/DXXOXP</a> (works as expected)
<br></blockquote></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 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 />
------=_Part_78_6611027.1390214948436--
.
Author: Roland Bock <rbock@eudoxos.de>
Date: Mon, 20 Jan 2014 12:31:22 +0100
Raw View
This is a multi-part message in MIME format.
--------------080406090704020109010709
Content-Type: text/plain; charset=UTF-8
Yes, sorry, was too quick...
On 2014-01-20 11:49, Vittorio Romeo wrote:
> This is not what I expect, since it also prints the parenthesis.
> The solution would be having a "variadic stringify function"
> |
> #define SSVPP_IMPL_STRINGIFYWITHCOMMAS(mIdx, mData, mArg) SSVPP_STRINGIFY(mArg)SSVPP_IF(mIdx, ", ", SSVPP_EMPTY())
> #define SSVPP_STRINGIFYWITHCOMMAS(...) SSVPP_FOREACH(SSVPP_IMPL_STRINGIFYWITHCOMMAS, SSVPP_EMPTY(), __VA_ARGS__)
> |
>
> However, it needs to be explicitly called, and the "raw argument"
> consistency fails here.
>
> On Monday, 20 January 2014 10:00:36 UTC+1, Roland Bock wrote:
>
> On 2014-01-20 09:53, Vittorio Romeo wrote:
> > http://ideone.com/B5hVDS
> >
> > This example shows un-intuitive behavior.
> > The "raw argument" is actually passed as multiple arguments, and
> does
> > not expand correctly.
> >
> > I would expect the program to print "1, 2, 3" or "1,2,3" -
> instead, it
> > fails to compile.
> >
> Did not check the other examples, but how about this:
>
> #define RAW(...) (__VA_ARGS__)
>
>
> http://ideone.com/DXXOXP (works as expected)
>
> --
>
> ---
> 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/.
--
---
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/.
--------------080406090704020109010709
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3DUTF-8" http-equiv=3D"Content-Type=
">
</head>
<body text=3D"#000000" bgcolor=3D"#FFFFFF">
<div class=3D"moz-cite-prefix">Yes, sorry, was too quick...<br>
<br>
On 2014-01-20 11:49, Vittorio Romeo wrote:<br>
</div>
<blockquote
cite=3D"mid:86a02b59-8c7f-4478-9f69-0ff53660c4eb@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">This is not what I expect, since it also prints the
parenthesis.=C2=A0<br>
The solution would be having a "variadic stringify function"
<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">
<pre><span style=3D" color:#ef2672;"><span style=3D"color: =
#800;" class=3D"styled-by-prettify">#define</span></span><span style=3D" co=
lor:#3e3d32;"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span></span><span style=3D" color:#ef2672;"><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">SSVPP_IMPL_STRINGIFYWITHCOMMAS</span></span><spa=
n style=3D" color:#e6e5e2;"><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(</span></span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">mIdx</span><span style=3D" color:#e6e5e2;"><span style=3D"color: #=
660;" class=3D"styled-by-prettify">,</span></span><span style=3D" color:#3e=
3d32;"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span></=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">mData</span>=
<span style=3D" color:#e6e5e2;"><span style=3D"color: #660;" class=3D"style=
d-by-prettify">,</span></span><span style=3D" color:#3e3d32;"><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span></span><span style=
=3D"color:=20
#000;" class=3D"styled-by-prettify">mArg</span><span style=3D" color:#e6e5e=
2;"><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span></spa=
n><span style=3D" color:#3e3d32;"><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> =C2=A0 </span></span><span style=3D" color:#ef2672;"><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">SSVPP_STRINGIFY</span=
></span><span style=3D" color:#e6e5e2;"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">mArg</span><span style=3D" color:#e6e5e2;"><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">)</span></span><span styl=
e=3D" color:#ef2672;"><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">SSVPP_IF</span></span><span style=3D" color:#e6e5e2;"><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(</span></span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">mIdx</span><span style=3D" color:#e=
6e5e2;"><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><=
/span><span st
yle=3D" color:#3e3d32;"><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span></span><span style=3D" color:#e6db74;"><span style=3D"color:=
#080;" class=3D"styled-by-prettify">",</span></span><span style=3D" color:=
#3e3d32;"><span style=3D"color: #080;" class=3D"styled-by-prettify"> </span=
></span><span style=3D" color:#e6db74;"><span style=3D"color: #080;" class=
=3D"styled-by-prettify">"</span></span><span style=3D" color:#e6e5e2;"><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">,</span></span><span =
style=3D" color:#3e3d32;"><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span></span><span style=3D" color:#ef2672;"><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">SSVPP_EMPTY</span></span><span style=
=3D" color:#e6e5e2;"><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">())</span></span></pre>
<pre><span style=3D" color:#ef2672;"><span style=3D"color: =
#800;" class=3D"styled-by-prettify">#define</span></span><span style=3D" co=
lor:#3e3d32;"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span></span><span style=3D" color:#ef2672;"><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">SSVPP_STRINGIFYWITHCOMMAS</span></span><span sty=
le=3D" color:#e6e5e2;"><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(...)</span></span><span style=3D" color:#3e3d32;"><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</span></span><span style=3D" col=
or:#ef2672;"><span style=3D"color: #000;" class=3D"styled-by-prettify">SSVP=
P_FOREACH</span></span><span style=3D" color:#e6e5e2;"><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span></span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">SSVPP_IMPL_STRINGIFYWITHCOMMAS</span><s=
pan style=3D" color:#e6e5e2;"><span style=3D"color: #660;" class=3D"styled-=
by-prettify">,</span></span><span style=3D" col
or:#3e3d32;"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan></span><span style=3D" color:#ef2672;"><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">SSVPP_EMPTY</span></span><span style=3D" color:#e=
6e5e2;"><span style=3D"color: #660;" class=3D"styled-by-prettify">(),</span=
></span><span style=3D" color:#3e3d32;"><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">__VA_ARGS__</span><span style=3D" color:#e6e5e2;"><=
span style=3D"color: #660;" class=3D"styled-by-prettify">)</span></span></p=
re>
</div>
</code></div>
<br>
However, it needs to be explicitly called, and the "raw
argument" consistency fails here.<br>
<br>
On Monday, 20 January 2014 10:00:36 UTC+1, Roland Bock wrote:
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On
2014-01-20 09:53, Vittorio Romeo wrote:
<br>
> <a moz-do-not-send=3D"true"
href=3D"http://ideone.com/B5hVDS" target=3D"_blank"
onmousedown=3D"this.href=3D'http://www.google.com/url?q\75htt=
p%3A%2F%2Fideone.com%2FB5hVDS\46sa\75D\46sntz\0751\46usg\75AFQjCNFN00duigtq=
jYQCPYDVTUIs2QmR1w';return
true;"
onclick=3D"this.href=3D'http://www.google.com/url?q\75http%3A=
%2F%2Fideone.com%2FB5hVDS\46sa\75D\46sntz\0751\46usg\75AFQjCNFN00duigtqjYQC=
PYDVTUIs2QmR1w';return
true;">http://ideone.com/B5hVDS</a>
<br>
>
<br>
> This example shows un-intuitive behavior.
<br>
> The "raw argument" is actually passed as multiple
arguments, and does
<br>
> not expand correctly.
<br>
>
<br>
> I would expect the program to print "1, 2, 3" or
"1,2,3" - instead, it
<br>
> fails to compile.
<br>
>
<br>
Did not check the other examples, but how about this:
<br>
<br>
#define RAW(...) (__VA_ARGS__)
<br>
<br>
<br>
<a moz-do-not-send=3D"true" href=3D"http://ideone.com/DXXOXP"
target=3D"_blank"
onmousedown=3D"this.href=3D'http://www.google.com/url?q\75htt=
p%3A%2F%2Fideone.com%2FDXXOXP\46sa\75D\46sntz\0751\46usg\75AFQjCNE0QEFIl6Ya=
qmdo5g6xSgGW64vK2Q';return
true;"
onclick=3D"this.href=3D'http://www.google.com/url?q\75http%3A=
%2F%2Fideone.com%2FDXXOXP\46sa\75D\46sntz\0751\46usg\75AFQjCNE0QEFIl6Yaqmdo=
5g6xSgGW64vK2Q';return
true;">http://ideone.com/DXXOXP</a> (works as expected)
<br>
</blockquote>
</div>
</div>
-- <br>
=C2=A0<br>
--- <br>
You received this message because you are subscribed to the Google
Groups "ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it,
send an email to <a class=3D"moz-txt-link-abbreviated" href=3D"mailto=
:std-proposals+unsubscribe@isocpp.org">std-proposals+unsubscribe@isocpp.org=
</a>.<br>
To post to this group, send email to <a class=3D"moz-txt-link-abbrevi=
ated" href=3D"mailto:std-proposals@isocpp.org">std-proposals@isocpp.org</a>=
..<br>
Visit this group at <a moz-do-not-send=3D"true"
href=3D"http://groups.google.com/a/isocpp.org/group/std-proposals/"=
>http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br>
</blockquote>
<br>
</body>
</html>
<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 />
--------------080406090704020109010709--
.
Author: Joel Falcou <joel.falcou@lri.fr>
Date: Mon, 20 Jan 2014 12:48:23 +0100
Raw View
This is a multi-part message in MIME format.
--------------090407090600010708050607
Content-Type: text/plain; charset=UTF-8; format=flowed
On 20/01/2014 12:31, Roland Bock wrote:
> Yes, sorry, was too quick...
Not sure if it helps but in our code base we have a STRIP macro that
removes parens around preprocessor arguments. Passing raw arguments is
just wrapping inside () and take care of it inside the macro itself.
Said macro:
https://github.com/MetaScale/nt2/blob/master/modules/boost/dispatch/include/boost/dispatch/preprocessor/strip.hpp
--
---
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/.
--------------090407090600010708050607
Content-Type: text/html; charset=UTF-8
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 20/01/2014 12:31, Roland Bock wrote:<br>
</div>
<blockquote cite="mid:52DD090A.6070506@eudoxos.de" type="cite">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<div class="moz-cite-prefix">Yes, sorry, was too quick...<br>
</div>
</blockquote>
<br>
Not sure if it helps but in our code base we have a STRIP macro that
removes parens around preprocessor arguments. Passing raw arguments
is just wrapping inside () and take care of it inside the macro
itself.<br>
<br>
Said macro:<br>
<br>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<a
href="https://github.com/MetaScale/nt2/blob/master/modules/boost/dispatch/include/boost/dispatch/preprocessor/strip.hpp">https://github.com/MetaScale/nt2/blob/master/modules/boost/dispatch/include/boost/dispatch/preprocessor/strip.hpp</a><br>
<br>
<br>
</body>
</html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email 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="http://groups.google.com/a/isocpp.org/group/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/</a>.<br />
--------------090407090600010708050607--
.
Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Mon, 20 Jan 2014 04:51:09 -0800 (PST)
Raw View
------=_Part_318_20904850.1390222269341
Content-Type: text/plain; charset=UTF-8
On Monday, January 20, 2014 9:53:04 AM UTC+1, Vittorio Romeo wrote:
>
> I would expect the program to print "1, 2, 3" or "1,2,3" - instead, it
> fails to compile.
In the following...
#define RAW(...) __VA_ARGS__
#define STRINGIFY(mArg) #mArg
#define MAKE_STRING(mArg) std::string(STRINGIFY(mArg))
An expansion of:
MAKE_STRING(RAW(1, 2, 3))
proceeds as follows:
1. First the mArg param to MAKE_STRING is identified. mArg=`RAW(1,2,3)`
2. Then mArg is macro expanded to mArg=`1,2,3`
3. Then mArg is substituted in the MAKE_STRING replacement list producing
`std::string(STRINGIFY(1,2,3))`
4. The MAKE_STRING invocation is now complete, and preprocessing restarts.
5. The `STRINGIFY(1,2,3)` invocation is identified, but it has 3 arguments
and expects 1. Error, stop.
There are several ways to fix this, but you will start heading into the
nesting rules and other things of which there is implementation variance.
My advice would be to study Clause 16 in the standard and then study
the implementation of the Boost.Preprocessor library if you are interested
in going deeper into "macro metaprogramming". You should do this before
even considering writing a proposal regarding the preprocessor.
On Monday, January 20, 2014 9:53:04 AM UTC+1, Vittorio Romeo wrote:
>
> http://ideone.com/B5hVDS
>
> This example shows un-intuitive behavior.
> The "raw argument" is actually passed as multiple arguments, and does not
> expand correctly.
>
> I would expect the program to print "1, 2, 3" or "1,2,3" - instead, it
> fails to compile.
>
--
---
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_318_20904850.1390222269341
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div><font face=3D"arial, sans-serif" color=3D"#000000">On=
Monday, January 20, 2014 9:53:04 AM UTC+1, Vittorio Romeo wrote:</font><bl=
ockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; border-l=
eft-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: s=
olid; padding-left: 1ex;"></blockquote></div><blockquote class=3D"gmail_quo=
te" style=3D"margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left=
-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><=
span style=3D"color: rgb(0, 0, 0); font-family: arial, sans-serif;">I would=
expect the program to print "1, 2, 3" or "1,2,3" - instead, it fails to co=
mpile.</span></blockquote><div><span style=3D"font-size: 12px; line-height:=
13px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: arial, sans=
-serif;"><br></span></div><div><span style=3D"font-size: 12px; line-height:=
13px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: arial, sans=
-serif;">In the following...</span></div><div><span style=3D"color: rgb(0, =
0, 0); font-family: arial, sans-serif; line-height: 13px; background-color:=
rgb(248, 248, 248); font-size: 12px; white-space: pre-wrap;"><br></span></=
div><div><span style=3D"color: rgb(0, 0, 0); font-family: arial, sans-serif=
; line-height: 13px; background-color: rgb(248, 248, 248); font-size: 12px;=
white-space: pre-wrap;">#define RAW(...) __VA_ARGS__</span></div><div><spa=
n style=3D"color: rgb(0, 0, 0); font-family: arial, sans-serif; line-height=
: 13px; background-color: rgb(248, 248, 248); font-size: 12px; white-space:=
pre-wrap;">#define STRINGIFY(mArg) #mArg</span></div><div><span style=3D"c=
olor: rgb(0, 0, 0); font-family: arial, sans-serif; line-height: 13px; back=
ground-color: rgb(248, 248, 248); font-size: 12px; white-space: pre-wrap;">=
#define MAKE_STRING(mArg) std::string(STRINGIFY(mArg))</span></div><div><fo=
nt face=3D"arial, sans-serif" color=3D"#000000"><br></font></div><div><font=
face=3D"arial, sans-serif" color=3D"#000000">An expansion of:</font></div>=
<div><font face=3D"arial, sans-serif" color=3D"#000000"><br></font></div><d=
iv><font face=3D"arial, sans-serif" color=3D"#000000"><span style=3D"font-s=
ize: 12px; line-height: 20px; white-space: pre-wrap; background-color: rgb(=
248, 248, 248);">MAKE_STRING</span><span class=3D"br0" style=3D"font-size: =
12px; white-space: pre-wrap; background-color: rgb(248, 248, 248); line-hei=
ght: 13px !important;">(</span><span style=3D"font-size: 12px; line-height:=
20px; white-space: pre-wrap; background-color: rgb(248, 248, 248);">RAW</s=
pan><span class=3D"br0" style=3D"font-size: 12px; white-space: pre-wrap; ba=
ckground-color: rgb(248, 248, 248); line-height: 13px !important;">(</span>=
<span class=3D"nu0" style=3D"font-size: 12px; white-space: pre-wrap; backgr=
ound-color: rgb(248, 248, 248); line-height: 13px !important;">1</span><spa=
n style=3D"font-size: 12px; line-height: 20px; white-space: pre-wrap; backg=
round-color: rgb(248, 248, 248);">, </span><span class=3D"nu0" style=3D"fon=
t-size: 12px; white-space: pre-wrap; background-color: rgb(248, 248, 248); =
line-height: 13px !important;">2</span><span style=3D"font-size: 12px; line=
-height: 20px; white-space: pre-wrap; background-color: rgb(248, 248, 248);=
">, </span><span class=3D"nu0" style=3D"font-size: 12px; white-space: pre-w=
rap; background-color: rgb(248, 248, 248); line-height: 13px !important;">3=
</span><span class=3D"br0" style=3D"font-size: 12px; white-space: pre-wrap;=
background-color: rgb(248, 248, 248); line-height: 13px !important;">)</sp=
an><span class=3D"br0" style=3D"font-size: 12px; white-space: pre-wrap; bac=
kground-color: rgb(248, 248, 248); line-height: 13px !important;">)</span><=
br></font></div><div><span class=3D"br0" style=3D"font-size: 12px; white-sp=
ace: pre-wrap; background-color: rgb(248, 248, 248); line-height: 13px !imp=
ortant;"><font face=3D"arial, sans-serif" color=3D"#000000"><br></font></sp=
an></div><div><font color=3D"#000000" face=3D"arial, sans-serif"><span styl=
e=3D"font-size: 12px; line-height: 13px; white-space: pre-wrap; background-=
color: rgb(248, 248, 248);">proceeds as follows:</span></font></div><div><s=
pan class=3D"br0" style=3D"font-size: 12px; white-space: pre-wrap; backgrou=
nd-color: rgb(248, 248, 248); line-height: 13px !important;"><font face=3D"=
arial, sans-serif" color=3D"#000000"><br></font></span></div><div><span cla=
ss=3D"br0" style=3D"font-size: 12px; white-space: pre-wrap; background-colo=
r: rgb(248, 248, 248); line-height: 13px !important;"><font face=3D"arial, =
sans-serif" color=3D"#000000">1. First the mArg param to MAKE_STRING is ide=
ntified. mArg=3D`RAW(1,2,3)`</font></span></div><div><span class=3D"br0" st=
yle=3D"font-size: 12px; white-space: pre-wrap; background-color: rgb(248, 2=
48, 248); line-height: 13px !important;"><font face=3D"arial, sans-serif" c=
olor=3D"#000000">2. Then mArg is macro expanded to mArg=3D`1,2,3`</font></s=
pan></div><div><font face=3D"arial, sans-serif" color=3D"#000000">3. Then m=
Arg is substituted in the MAKE_STRING replacement list producing `std::stri=
ng(STRINGIFY(1,2,3))`</font></div><div><font face=3D"arial, sans-serif" col=
or=3D"#000000">4. The MAKE_STRING invocation is now complete, and preproces=
sing restarts.</font></div><div><font face=3D"arial, sans-serif" color=3D"#=
000000">5. The `STRINGIFY(1,2,3)` invocation is identified, but it has 3 ar=
guments and expects 1. Error, stop.</font></div><div><font face=3D"ar=
ial, sans-serif" color=3D"#000000"><br></font></div><div><font color=3D"#00=
0000" face=3D"arial, sans-serif">There are several ways to fix this, but yo=
u will start heading into the nesting rules and other things of which there=
is implementation variance.</font></div><div><font color=3D"#000000" face=
=3D"arial, sans-serif"><br></font></div><div><font color=3D"#000000" face=
=3D"arial, sans-serif">My advice would be to study Clause 16 in the standar=
d and then study the implementation of the Boost.Preprocessor lib=
rary if you are interested in going deeper into "macro metaprogramming". &n=
bsp;You should do this before even considering writing a proposal regarding=
the preprocessor.</font></div><div><br></div><font face=3D"arial, sans-ser=
if" color=3D"#000000"><br>On Monday, January 20, 2014 9:53:04 AM UTC+1, Vit=
torio Romeo wrote:</font><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"><font face=3D"arial, sans-serif" color=3D"#000000"><a href=3D"h=
ttp://ideone.com/B5hVDS" target=3D"_blank" onmousedown=3D"this.href=3D'http=
://www.google.com/url?q\75http%3A%2F%2Fideone.com%2FB5hVDS\46sa\75D\46sntz\=
0751\46usg\75AFQjCNFN00duigtqjYQCPYDVTUIs2QmR1w';return true;" onclick=3D"t=
his.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fideone.com%2FB5hVDS\=
46sa\75D\46sntz\0751\46usg\75AFQjCNFN00duigtqjYQCPYDVTUIs2QmR1w';return tru=
e;">http://ideone.com/B5hVDS</a><br><br>This example shows un-intuitive beh=
avior.</font><div><font face=3D"arial, sans-serif" color=3D"#000000">The "r=
aw argument" is actually passed as multiple arguments, and does not expand =
correctly.</font></div><div><font face=3D"arial, sans-serif" color=3D"#0000=
00"><br></font></div><div><font face=3D"arial, sans-serif" color=3D"#000000=
">I would expect the program to print "1, 2, 3" or "1,2,3" - instead, it fa=
ils to compile.</font></div></div></blockquote></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 />
------=_Part_318_20904850.1390222269341--
.
Author: George Makrydakis <irrequietus@gmail.com>
Date: Mon, 20 Jan 2014 16:13:46 +0200
Raw View
------VLT51EHOJ9FO4NYWUKIAXFRAS7LU1T
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
This is exactly the reason why this addition would not bring about any subs=
tantial benefit.
We can handle "raw" macro arguments using current preprocessor metaprogramm=
ing techniques; if anything we should improve certain semantics in __VA_ARG=
S__ (it has been discussed in the past). But things like these usually hit =
a no - wall because "C has to do it first", just as Ville said.
Joel Falcou <joel.falcou@lri.fr> wrote:
>On 20/01/2014 12:31, Roland Bock wrote:
>> Yes, sorry, was too quick...
>
>Not sure if it helps but in our code base we have a STRIP macro that=20
>removes parens around preprocessor arguments. Passing raw arguments is=20
>just wrapping inside () and take care of it inside the macro itself.
>
>Said macro:
>
>https://github.com/MetaScale/nt2/blob/master/modules/boost/dispatch/includ=
e/boost/dispatch/preprocessor/strip.hpp
>
>
>--=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 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/.
--=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/.
------VLT51EHOJ9FO4NYWUKIAXFRAS7LU1T
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html><head><meta content=3D"text/html; charset=3DUTF-8" http-equiv=3D"Cont=
ent-Type" /><meta content=3D"text/html; charset=3DUTF-8" http-equiv=3D"Cont=
ent-Type" /><meta http-equiv=3D"content-type" content=3D"text/html; charset=
=3DUTF-8" /></head><body bgcolor=3D"#FFFFFF" text=3D"#000000"><p dir=3D"ltr=
">This is exactly the reason why this addition would not bring about any su=
bstantial benefit.</p>
<p dir=3D"ltr">We can handle "raw" macro arguments using current preprocess=
or metaprogramming techniques; if anything we should improve certain semant=
ics in __VA_ARGS__ (it has been discussed in the past). But things like the=
se usually hit a no - wall because "C has to do it first", just as Ville sa=
id.<br>
</p>
<br><br><div class=3D"gmail_quote">Joel Falcou <joel.falcou@lri.fr> w=
rote:<blockquote class=3D"gmail_quote" style=3D"margin: 0pt 0pt 0pt 0.8ex; =
border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
=20
=20
=20
=20
<div class=3D"moz-cite-prefix">On 20/01/2014 12:31, Roland Bock wrote:<=
br />
</div>
<blockquote cite=3D"mid:52DD090A.6070506@eudoxos.de" type=3D"cite">
=20
<div class=3D"moz-cite-prefix">Yes, sorry, was too quick...<br />
</div>
</blockquote>
<br />
Not sure if it helps but in our code base we have a STRIP macro that
removes parens around preprocessor arguments. Passing raw arguments
is just wrapping inside () and take care of it inside the macro
itself.<br />
<br />
Said macro:<br />
<br />
=20
<a href=3D"https://github.com/MetaScale/nt2/blob/master/modules/boost/d=
ispatch/include/boost/dispatch/preprocessor/strip.hpp">https://github.com/M=
etaScale/nt2/blob/master/modules/boost/dispatch/include/boost/dispatch/prep=
rocessor/strip.hpp</a><br />
<br />
<br />
=20
<p></p>
</blockquote></div></body></html>
<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 />
------VLT51EHOJ9FO4NYWUKIAXFRAS7LU1T--
.