Boost logo

Boost Users :

Subject: [Boost-users] [BOOST.PREPROCESSOR] Use BOOST_PP_REPEAT in macros?
From: Sergey Zhuravlev (sergey4zhuravlev_at_[hidden])
Date: 2013-09-09 09:06:34


Write code:
//////////////////
#define ARGS_AMOUNT 9
#define INTERNAL_GENERATE_MEMBER_APPLY_CLASS(_, ARG_COUNTER, MemberName)\
  template<class TClassWithMember BOOST_PP_COMMA_IF(ARG_COUNTER)
BOOST_PP_ENUM_PARAMS(ARG_COUNTER, class TArg)>\
  result_type operator()(\
    TClassWithMember& classWithMember BOOST_PP_COMMA_IF(ARG_COUNTER)\
    BOOST_PP_ENUM_BINARY_PARAMS(ARG_COUNTER, TArg, &arg)) const\
    {\
       classWithMember.MemberName(BOOST_PP_ENUM_PARAMS(ARG_COUNTER, arg));\
    }

#define DECLARE_MEMBER_APPLY_CLASS(TMemberApplyClassName, MemberName)\
  template<class TResultType>\
  struct TMemberApplyClassName\
  {\
     typedef TResultType result_type;\
     BOOST_PP_REPEAT(ARGS_AMOUNT, INTERNAL_GENERATE_MEMBER_APPLY_CLASS,
MemberName)\
  };
#undef ARGS_AMOUNT
//////////////////

DECLARE_MEMBER_APPLY_CLASS(TClassName, MemberName) declare class template
closer to boost::apply, but my declared class call member MemberName:
f.MemberName(args...); opposite f.operator()(args...) at boost::apply.
Code not work correctly, because ARGS_AMOUNT not replaced to number 9
internally. ARGS_AMOUNT preserved after all macros substitution.
If manualy replace text "ARGS_AMOUNT" at "call" for BOOST_PP_REPEAT in
macros DECLARE_MEMBER_APPLY_CLASS to 9, then code generated and work
correctly.
Why it does? How preserve valuable name of const ARGS_AMOUNT?
Now temporarily maualy replace ARGS_AMOUNT to 9 and write comment about
this hardcoded const 9:
BOOST_PP_REPEAT(9 /*max amount of arguments for MemberName*/,
INTERNAL_GENERATE_MEMBER_APPLY_CLASS, MemberName)\



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net