|
Boost : |
From: vesa_karvonen (vesa_karvonen_at_[hidden])
Date: 2002-02-18 11:55:02
--- In boost_at_y..., "craigp98072" <craigp98072_at_y...> wrote:
> I've been trying to learn how to use this library effectively, and
> have a couple of questions.
>
> In trying to come up with a (cheesy) persistent class library,
> I have persistent classes define a describe function which
> enumerates over the members. For example:
[snip]
> The question is: why does this fail to compile?
It doesn't - at least not on my system with:
- MSVC++ 6.0 sp5
- latest sources from the CVS
- #include <boost/preprocessor.hpp> (i.e. included all macros)
I'll be happy to try to help more if you send me (don't send it to
the list) as (compressed) attachments:
- a minimal test source that reproduces this problem,
- the entire output from the preprocessor. You can get it by using
the -E option.
> If I change the DESCRIBE_MEMFN_GEN to not use P, but
> Supplier_Tuple_Member_List directly, it works. Why can't I pass a
> type list as a macro parameter in BOOST_PP_REPEAT?
This sounds like a preprocessor bug. I recommend that you try the
same source with g++ as well. However, a minimal source I copy-pasted
together works on MSVC++ 6.0 sp5 and g++ 2.95.3 (cygwin).
> Also, I tried doing some arithmetic on list indices. For example, I
> tried to add 1 to the first index:
>
> #define DESCRIBE_MEMFN_GEN(I, P) \
> v.member( BOOST_PP_LIST_AT(Supplier_Tuple_Member_List,I+1),
> BOOST_PP_LIST_AT(Supplier_Tuple_Name_List,I) );
>
> This also fails to compile (same error as above). Am I missing
> something? Any help is appreciated.
Unfortunately the preprocessor does not understand expressions like
I+1. You need to use BOOST_PP_ADD(I,1) or BOOST_PP_INC(I).
...
The following is the source I used for testing:
<-- -->
#include <boost/preprocessor.hpp>
#define Supplier_Tuple_Type_List\
BOOST_PP_TUPLE_TO_LIST(4,(S_Num, S_Name, Status, City))
#define Supplier_Tuple_Member_List\
BOOST_PP_TUPLE_TO_LIST(4,(num_, name_, status_, city_))
#define Supplier_Tuple_Name_List\
BOOST_PP_TUPLE_TO_LIST(4,("S#", "SName", "Status", "City"))
// just hard-code Supplier_Tuple_Name_List for now
// P = member list
#define DESCRIBE_MEMFN_GEN(I, P)\
v.member( BOOST_PP_LIST_AT(P,I), BOOST_PP_LIST_AT
(Supplier_Tuple_Name_List,I) );
#define PCLASS(name, type_list, member_list, name_list)\
template<typename V>\
void describe(V& v)\
{\
BOOST_PP_REPEAT( BOOST_PP_LIST_SIZE(type_list),
DESCRIBE_MEMFN_GEN, Supplier_Tuple_Member_List );\
}
PCLASS
(x,Supplier_Tuple_Type_List,Supplier_Tuple_Member_List,Supplier_Tuple_
Name_List)
<-- -->
And the following is the output I get:
<-- -->
template<typename V> void describe(V& v) { v.member( num_, "S#" );
v.member( name_, "SName" ); v.member( status_, "Status" ); v.member(
city_, "City" );; }
<-- -->
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk