<div dir="ltr"><div style>Write code:</div><div style>//////////////////<br></div><div style>#define ARGS_AMOUNT 9</div><div>#define INTERNAL_GENERATE_MEMBER_APPLY_CLASS(_, ARG_COUNTER, MemberName)\</div><div>  template&lt;class TClassWithMember BOOST_PP_COMMA_IF(ARG_COUNTER) BOOST_PP_ENUM_PARAMS(ARG_COUNTER, class TArg)&gt;\</div>
<div>  result_type operator()(\</div><div>    TClassWithMember&amp; classWithMember BOOST_PP_COMMA_IF(ARG_COUNTER)\</div><div>    BOOST_PP_ENUM_BINARY_PARAMS(ARG_COUNTER, TArg, &amp;arg)) const\</div><div>    {\</div><div>
       classWithMember.MemberName(BOOST_PP_ENUM_PARAMS(ARG_COUNTER, arg));\</div><div>    }</div><div><br></div><div>#define DECLARE_MEMBER_APPLY_CLASS(TMemberApplyClassName, MemberName)\</div><div>  template&lt;class TResultType&gt;\</div>
<div>  struct TMemberApplyClassName\</div><div>  {\</div><div>     typedef TResultType result_type;\</div><div>     BOOST_PP_REPEAT(ARGS_AMOUNT, INTERNAL_GENERATE_MEMBER_APPLY_CLASS, MemberName)\</div><div>  };</div><div>
#undef ARGS_AMOUNT</div><div>//////////////////<br></div><div><br></div><div>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.</div>
<div style>Code not work correctly, because ARGS_AMOUNT not replaced to number 9 internally. ARGS_AMOUNT preserved after all macros substitution.</div><div style>If manualy replace text &quot;ARGS_AMOUNT&quot; at &quot;call&quot; for BOOST_PP_REPEAT in macros DECLARE_MEMBER_APPLY_CLASS to 9, then code generated and work correctly.</div>
<div style>Why it does? How preserve valuable name of const ARGS_AMOUNT? </div><div style>Now temporarily maualy replace ARGS_AMOUNT to 9 and write comment about this hardcoded const 9:</div><div style>BOOST_PP_REPEAT(9 /*max amount of arguments for MemberName*/, INTERNAL_GENERATE_MEMBER_APPLY_CLASS, MemberName)\<br>
</div></div>

