Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Preprocessor sequence of "pairs"

Received: by 10.224.70.131 with SMTP id d3mr95564qaj.0.1348645535181;
        Wed, 26 Sep 2012 00:45:35 -0700 (PDT)
X-BeenThere: boost-list@googlegroups.com
Received: by 10.229.106.74 with SMTP id w10ls1444457qco.6.gmail; Wed, 26 Sep
 2012 00:45:35 -0700 (PDT)
Received: by 10.224.31.20 with SMTP id w20mr92344qac.2.1348645535051;
        Wed, 26 Sep 2012 00:45:35 -0700 (PDT)
Received: by 10.224.31.20 with SMTP id w20mr92343qac.2.1348645535041;
        Wed, 26 Sep 2012 00:45:35 -0700 (PDT)
Return-Path: <boost-users-boun...@lists.boost.org>
Received: from wowbagger.osl.iu.edu (wowbagger.osl.iu.edu. [129.79.245.252])
        by gmr-mx.google.com with ESMTP id t6si828817qcp.0.2012.09.26.00.45.34;
        Wed, 26 Sep 2012 00:45:35 -0700 (PDT)
Received-SPF: neutral (google.com: 129.79.245.252 is neither permitted nor denied by best guess record for domain of boost-users-boun...@lists.boost.org) client-ip=129.79.245.252;
Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 129.79.245.252 is neither permitted nor denied by best guess record for domain of boost-users-boun...@lists.boost.org) smtp.mail=boost-users-boun...@lists.boost.org
Received: from wowbagger.osl.iu.edu (localhost [127.0.0.1])
	by wowbagger.osl.iu.edu (Postfix) with ESMTP id ABDE92F9017;
	Wed, 26 Sep 2012 03:45:33 -0400 (EDT)
X-Original-To: boost-us...@lists.boost.org
Delivered-To: boost-us...@lists.boost.org
Received: from blu0-omc2-s23.blu0.hotmail.com (blu0-omc2-s23.blu0.hotmail.com
	[65.55.111.98])
	by wowbagger.osl.iu.edu (Postfix) with ESMTP id 7F5FF2F8491
	for <boost-us...@lists.boost.org>; Wed, 26 Sep 2012 03:44:55 -0400 (EDT)
Received: from BLU162-W21 ([65.55.111.71]) by blu0-omc2-s23.blu0.hotmail.com
	with Microsoft SMTPSVC(6.0.3790.4675); 
	Wed, 26 Sep 2012 00:44:54 -0700
Message-ID: <BLU162-W2159E6E07F6E4A35F8DC33969C0@phx.gbl>
X-Originating-IP: [184.175.22.237]
From: Nathan Ridge <zeratul...@hotmail.com>
To: Boost Mailing List <boost-us...@lists.boost.org>
Date: Wed, 26 Sep 2012 07:44:54 +0000
Importance: Normal
In-Reply-To: <c84398013c748e54d1089438398a1791.squir...@webmail.cs.wisc.edu>
References: <c84398013c748e54d1089438398a1791.squir...@webmail.cs.wisc.edu>
MIME-Version: 1.0
X-OriginalArrivalTime: 26 Sep 2012 07:44:54.0952 (UTC)
	FILETIME=[D1CA2280:01CD9BBA]
Subject: Re: [Boost-users] Preprocessor sequence of "pairs"
X-BeenThere: boost-us...@lists.boost.org
X-Mailman-Version: 2.1.12
Precedence: list
Reply-To: boost-us...@lists.boost.org
List-Id: Boost Users mailing list <boost-users.lists.boost.org>
List-Unsubscribe: <http://lists.boost.org/mailman/options.cgi/boost-users>,
	<mailto:boost-users-requ...@lists.boost.org?subject=unsubscribe>
List-Archive: <http://lists.boost.org/boost-users>
List-Post: <mailto:boost-us...@lists.boost.org>
List-Help: <mailto:boost-users-requ...@lists.boost.org?subject=help>
List-Subscribe: <http://lists.boost.org/mailman/listinfo.cgi/boost-users>,
	<mailto:boost-users-requ...@lists.boost.org?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: boost-users-boun...@lists.boost.org
Errors-To: boost-users-boun...@lists.boost.org


> What I want to do is something like the following:
>
> #include <boost/preprocessor/seq/for_each.hpp>
>
> #define DEFINE_FIELD(r, os, field_pair) [....]
>
> #define DEFINE_STRUCT(struct_name, fields) \
> struct struct_name { \
> BOOST_PP_SEQ_FOR_EACH(DEFINE_FIELD, ~, fields) \
> }
>
> DEFINE_STRUCT(mystruct, (int, x)(int, y)(double, z))
>
> but this doesn't work, because the sequence is made up of pairs instead of
> single preprocessor arguments. (GCC complains about "macro
> "BOOST_PP_SEQ_SIZE_0" passed 2 arguments, but takes just 1" and same for
> PP_EXPR_IIF_0.)
>
> I can get it to work by double-parenthesizing the stuff in the sequence
> (saying "((int, x))((int, y))((double, z))") then defining DEFINE_FIELD as
> follows:
>
> #define DEFINE_FIELD_REAL(type, name) type name;
> #define DEFINE_FIELD(r, os, field_pair) DEFINE_FIELD_REAL field_pair
>
> but this is less than optimal. Is there a way that I can do this easily,
> or would I effectively have to re-implement SEQ_FOR_EACH? (And how hard
> would that be if it's necessary?)

Given INPUT of the form (a1, b1)(a2, b2)(a3, b3)...(an, bn)

you can transform it into OUTPUT of the form ((a1, b1))((a2, b2))((a3, b3))...((an, bn))

as follows:

#define ADD_PAREN_1(A, B) ((A, B)) ADD_PAREN_2
#define ADD_PAREN_2(A, B) ((A, B)) ADD_PAREN_1
#define ADD_PAREN_1_END
#define ADD_PAREN_2_END
#define OUTPUT BOOST_PP_CAT(ADD_PAREN_1 INPUT,_END)

You can then process the double-parenthesized sequence with SEQ_FOR_EACH 
like you want.

Regards,
Nate
 		 	   		  
_______________________________________________
Boost-users mailing list
Boost-us...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users