220 8720 <f5e84374-d3a7-4046-a674-33259e520ee5@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: jgottman6@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: "Raw" preprocessor macro arguments
Date: Sun, 19 Jan 2014 17:06:18 -0800 (PST)
Lines: 420
Approved: news@gmane.org
Message-ID: <f5e84374-d3a7-4046-a674-33259e520ee5@isocpp.org>
References: <c0398870-b265-4d02-a814-ad84a472520c@isocpp.org>
 <47db64d6-64fb-4243-bded-e36fc8be30b2@isocpp.org>
 <0948fc8a-2191-4ab0-97df-cf354a470828@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_550_15354894.1390179978103"
X-Trace: ger.gmane.org 1390179974 8560 80.91.229.3 (20 Jan 2014 01:06:14 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 20 Jan 2014 01:06:14 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBD7LHGWIQEPRBCXN6GLAKGQELERNV6I@isocpp.org Mon Jan 20 02:06:21 2014
Return-path: <std-proposals+bncBD7LHGWIQEPRBCXN6GLAKGQELERNV6I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pa0-f72.google.com ([209.85.220.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD7LHGWIQEPRBCXN6GLAKGQELERNV6I@isocpp.org>)
	id 1W53Jk-0005nX-I7
	for gclcip-std-proposals@m.gmane.org; Mon, 20 Jan 2014 02:06:21 +0100
Original-Received: by mail-pa0-f72.google.com with SMTP id rd3sf16237883pab.7
        for <gclcip-std-proposals@m.gmane.org>; Sun, 19 Jan 2014 17:06:19 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=tmBdVmdrVe5CTBREq5/SSf0laGBvz8QA3C2xsrTUP/o=;
        b=GETeMomadzcVqutVTf6I1KcaFvNv3qoak6aCqnEHyVrfVOuo/XCQ8mjobg/fgzHYwp
         oIze10yfhy+oCtZW+cB14eS/pixnkToOOqnJvNA1/p5IirwGY8cUWN51SFnhKuVFs+Ip
         FvcJHybH6eDPZTEhUIoCBizesjqWbk8xCYqy4bNOtnozBxtwRgMBFdjD/CLARoQjUdMI
         ReLZBR/GJkjFgecDe122BfdlmqGKuFWteau7dNgzEdQfRg597ryVqfgJT0q+1JtQhnQX
         D/TrM5E4+iOH8AabUkcHRrIO/jsI9sYQRKmMTsoS6s6Mj0spmnaq7D2AIr8K6BMhyejD
         lfJw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=tmBdVmdrVe5CTBREq5/SSf0laGBvz8QA3C2xsrTUP/o=;
        b=eVYYm5biwFUFyhf1kYg7Pjt6HpgXvC55bSwxjjg94fCpOHILKVkX98KV9JeQ9A35GC
         vY5U5yjHNE6WwsGIU0BY6v3EAClsssBheInlEF3xnbSvxCcAqtsUSQ5g61lJgQSkoyjH
         9+ftAlEB+aG58kGbxdQ0B+E/FzuN8SI6R/Ct3TRoV5JkveNHsshi/I13tP9BfPPqtl9j
         KXEm0+E1gXJwlwMpcwFvj/JG99IEuIagAJrCWZ7Y1l5dg+hm7XCgzy4xF8DFUD9LM3//
         GOEiT/eXZE+PP1C+wGfq7d31evnGnI23xOMBpi6CT9o9ykoi8vdFf8JwQGiD4XRq/JRH
         JU0g==
X-Gm-Message-State: ALoCoQkypElHb9jr9mU6EBB6iK7xs290/fskxCU0m7qt0EtDn8IPWO4MyCpYph5npZDdmMRVhckO
X-Received: by 10.66.66.35 with SMTP id c3mr5557092pat.12.1390179979155;
        Sun, 19 Jan 2014 17:06:19 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.127.110 with SMTP id nf14ls286718qeb.44.gmail; Sun, 19 Jan
 2014 17:06:18 -0800 (PST)
X-Received: by 10.140.38.9 with SMTP id s9mr390qgs.33.1390179978515;
        Sun, 19 Jan 2014 17:06:18 -0800 (PST)
In-Reply-To: <0948fc8a-2191-4ab0-97df-cf354a470828@isocpp.org>
X-Original-Sender: jgottman6@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:8720
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8720>

------=_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.&nbsp; 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">&lt;</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">&gt;)</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">&lt;</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">&gt;</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. &nbsp;The argument=
 to RAW will be parsed in turn as two arguments and not one. &nbsp;It shoul=
d be:<div><br></div><div>&nbsp; &nbsp; #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)">&lt;</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)">=
&nbsp;</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)">&gt;),</span><span=
 style=3D"font-family:monospace;background-color:rgb(250,250,250);color:rgb=
(0,0,0)">&nbsp;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)">&nbsp;<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. &nbsp;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>,&nbsp;even if potentially&nbsp;<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.&nbsp;<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 =
"&lt;int, int&gt;" 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">&lt;</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">&gt;,</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 "&lt;int, int&gt;" 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">&lt;</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">&gt;),</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>&nbsp; &nbsp; (std::pair&lt;int, int&gt;) 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&lt;int, int&gt;` - 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.&nbsp;</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">&lt;</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">&gt;),</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">&lt;=
 __R &gt; </span><span style=3D"color:#008">&lt;prefix&gt;</span><span styl=
e=3D"color:#000"> &lt;(&gt; &lt;...&gt; &lt;)&gt; </span><span style=3D"col=
or:#008">&lt;suffix&gt;</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">&amp;</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">&nbsp; &n=
bsp; &nbsp;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>&nbsp; &nbsp; &nbsp;</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>&nbsp; &nbsp; &nbsp;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>&nbsp; &nbs=
p; &nbsp;</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 />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to 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--

.
