$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: craigp98072 (craigp98072_at_[hidden])
Date: 2002-02-17 22:47:46
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:
class Supplier_Tuple
{
  S_Num num_;
  S_Name name_;
  Status status_;
  City city_;
public:
  template<typename V>
  void describe(V& v)
  {
    v.member( num_, "S#" );
    v.member( name_, "S_Name" );
    v.member( status_, "Status" );
    v.member( city_, "City" );
  }
};
I would like to automate this with a macro by giving it 3 lists: 
member types, member names, and attribute names (the "S#", "S_Name", 
etc in the example above).
Here's what I came up with:
#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 ); \
  } \
The question is: why does this fail to compile? The error is (MSVC++ 
6.0 sp5): error C2065: 'BOOST_PP_TUPLE3_ELEM0' : undeclared 
identifier. 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?
Working example:
#define DESCRIBE_MEMFN_GEN(I, P) \
  v.member( BOOST_PP_LIST_AT(Supplier_Tuple_Member_List,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, 0 ); \
  } \
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.
cheers!
--craig