<div dir="ltr"><p>Hi,</p><p></p><p>I've written some preprocessor directives to generate functions for a class. With Boost 1.55 everything works fine with gcc and clang. When I try to change to Boost 1.57 I've got some strange compile errors.</p><p></p><p></p><p>I'm happy if someone could help.</p><p></p><p>Thanks</p><p>Franz<br></p><p><br></p> <p>gcc 4.9.1 failed with error:</p><p></p><p> test.cpp:33:1: error: macro "BOOST_PP_SEQ_ELEM_III" requires 2 arguments, but only 1 given<br> )<br> ^<br> test.cpp:33:1: error: macro "BOOST_PP_VARIADIC_ELEM_2" requires 4 arguments, but only 2 given<br> test.cpp:60:1: error: macro "BOOST_PP_SEQ_ELEM_III" requires 2 arguments, but only 1 given<br> MY_FUNCTION_BEGIN((b))<br> ^<br> test.cpp:60:1: error: macro "BOOST_PP_VARIADIC_ELEM_2" requires 4 arguments, but only 2 give</p><p><br></p><p>clang 3.5.0 failed with error:</p><p> test.cpp:30:3: error: too few arguments provided to function-like macro invocation<br> MY_FUNCTIONS( \<br> ^<br> test.cpp:25:25: note: expanded from macro 'MY_FUNCTIONS'<br> BOOST_PP_SEQ_FOR_EACH(FUNCTION_DECL, _, seq)<br> ^<br> ..../boost.1_57_0/boost/preprocessor/seq/for_each.hpp:26:67: note: expanded from macro 'BOOST_PP_SEQ_FOR_EACH'<br> # define BOOST_PP_SEQ_FOR_EACH(macro, data, seq) BOOST_PP_FOR((macro, data, seq (nil)), BOOST_PP_SEQ_FOR_EACH_P, BOOST_PP_SEQ_FOR_EACH_O, BOOST_PP_SEQ_FOR_EACH_M)<br> ^<br> ..../boost.1_57_0/boost/preprocessor/repetition/detail/for.hpp:22:78: note: expanded from macro 'BOOST_PP_FOR_1'<br> # define BOOST_PP_FOR_1(s, p, o, m) BOOST_PP_FOR_1_C(BOOST_PP_BOOL(p(2, s)), s, p, o, m)<br> ^<br> note: (skipping 18 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)<br> packages/boost/boost_i4/boost/preprocessor/seq/elem.hpp:22:39: note: expanded from macro 'BOOST_PP_SEQ_ELEM'<br> # define BOOST_PP_SEQ_ELEM(i, seq) BOOST_PP_SEQ_ELEM_I(i, seq)<br> ^<br> packages/boost/boost_i4/boost/preprocessor/seq/elem.hpp:41:45: note: expanded from macro 'BOOST_PP_SEQ_ELEM_I'<br> # define BOOST_PP_SEQ_ELEM_I(i, seq) BOOST_PP_SEQ_ELEM_II(BOOST_PP_SEQ_ELEM_ ## i seq)<br> ^<br> packages/boost/boost_i4/boost/preprocessor/seq/elem.hpp:43:62: note: expanded from macro 'BOOST_PP_SEQ_ELEM_II'<br> # define BOOST_PP_SEQ_ELEM_II(im) BOOST_PP_SEQ_ELEM_III(im)<br> ^<br> packages/boost/boost_i4/boost/preprocessor/seq/elem.hpp:44:13: note: macro 'BOOST_PP_SEQ_ELEM_III' defined here<br> # define BOOST_PP_SEQ_ELEM_III(x, _) x<br></p><p><br></p><p>The program is:</p> #include <iostream><br> <br> #ifndef BOOST_PP_VARIADICS<br> #define BOOST_PP_VARIADICS<br> #endif<br> <br> #include <boost/preprocessor.hpp><br> <br> #define ADD_CONST_REF(op, data, elem) elem const &<br> <br> #define FUNCTION_DECL(r, data, tup) \<br> double BOOST_PP_TUPLE_ELEM(0, tup) \<br> BOOST_PP_IF(BOOST_PP_LIST_IS_NIL(BOOST_PP_TUPLE_TO_LIST(BOOST_PP_TUPLE_ELEM(1, tup))), \<br> (), \<br> BOOST_PP_SEQ_TO_TUPLE( \<br> BOOST_PP_SEQ_TRANSFORM( \<br> ADD_CONST_REF, \<br> _, \<br> BOOST_PP_TUPLE_TO_SEQ(BOOST_PP_LIST_TO_TUPLE(BOOST_PP_TUPLE_TO_LIST(BOOST_PP_TUPLE_ELEM(1, tup)))) \<br> ) \<br> ) \<br> ) \<br> const;<br> <br> #define MY_FUNCTIONS(seq) \<br> BOOST_PP_SEQ_FOR_EACH(FUNCTION_DECL, _, seq)<br> <br> class Foo<br> {<br> public:<br> MY_FUNCTIONS( \<br> ((a, (int))) \<br> ((b) ) \<br> )<br> };<br> <br> #define ADD_ARG(op, data, elem) elem const & BOOST_PP_CAT(a_, elem)<br> <br> #define MY_FUNCTION_BEGIN(tup) \<br> double Foo::BOOST_PP_TUPLE_ELEM(0, tup) \<br> BOOST_PP_IF(BOOST_PP_LIST_IS_NIL(BOOST_PP_TUPLE_TO_LIST(BOOST_PP_TUPLE_ELEM(1, tup))), \<br> (), \<br> BOOST_PP_SEQ_TO_TUPLE( \<br> BOOST_PP_SEQ_TRANSFORM( \<br> ADD_ARG, \<br> _, \<br> BOOST_PP_TUPLE_TO_SEQ(BOOST_PP_LIST_TO_TUPLE(BOOST_PP_TUPLE_TO_LIST(BOOST_PP_TUPLE_ELEM(1, tup)))) \<br> ) \<br> ) \<br> ) const \<br> {<br> <br> #define MY_FUNCTION_END() }<br> <br> MY_FUNCTION_BEGIN((a, (int)))<br> {<br> std::cout << "Foo::a(" << a_int << ")\n";<br> }<br> MY_FUNCTION_END()<br> <br> MY_FUNCTION_BEGIN((b))<br> {<br> std::cout << "Foo::b()\n";<br> }<br> MY_FUNCTION_END()<br> <br> int main()<br> {<br> Foo f;<br> f.a(42);<br> f.b();<br> <br> return 0;<br> }<br></div>