[BOOST.PREPROCESSOR] Use BOOST_PP_REPEAT in macros?
Write code:
//////////////////
#define ARGS_AMOUNT 9
#define INTERNAL_GENERATE_MEMBER_APPLY_CLASS(_, ARG_COUNTER, MemberName)\
template
On 9/9/2013 9:06 AM, Sergey Zhuravlev wrote:
Write code: ////////////////// #define ARGS_AMOUNT 9 #define INTERNAL_GENERATE_MEMBER_APPLY_CLASS(_, ARG_COUNTER, MemberName)\ template
\ 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?
When you invoke DECLARE_MEMBER_APPLY_CLASS the macro ARGS_AMOUNT is not defined. Macros do not get expanded until you invoke them.
participants (2)
-
Edward Diener
-
Sergey Zhuravlev