Boost C++ Libraries: Ticket #4456: BOOST_PP_SEQ_FOLD_RIGHT completely broken https://svn.boost.org/trac10/ticket/4456 <p> The following program is adapted from the macro BOOST_PP_SEQ_CAT that concatenates the elements of a sequence to a string: </p> <p> (a)(b)(c)(d) ==&gt; "abcd" </p> <p> BOOST_PP_SEQ_CAT is built upon BOOST_SEQ_FOLD_LEFT; by analogy, one would expect that macro REVCAT, written after BOOST_PP_SEQ_CAT, but using BOOST_PP_SEQ_FOLD_RIGHT, builds a reversed string "dcba". This is not the case, in fact, the program does not even compile, because BOOST_PP_FOLD_RIGHT is currently completely broken. </p> <pre class="wiki">#include &lt;boost/preprocessor.hpp&gt; # define REVCAT(seq) \ BOOST_PP_IF( \ BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(seq)), \ REVCAT_I, \ BOOST_PP_SEQ_HEAD(seq) BOOST_PP_TUPLE_EAT_1 \ )(seq) \ /**/ # define REVCAT_I(seq) BOOST_PP_SEQ_FOLD_RIGHT(REVCAT_O, BOOST_PP_SEQ_HEAD(seq), BOOST_PP_SEQ_TAIL(seq)) # # define REVCAT_O(s, st, elem) REVCAT_O_I(st, elem) # define REVCAT_O_I(a, b) a ## b const char x[] = BOOST_PP_STRINGIZE(BOOST_PP_SEQ_CAT((a)(b)(c)(d))); # pragma warning just a marker const char revx[] = BOOST_PP_STRINGIZE(REVCAT((a)(b)(c)(d))); </pre><p> int main() { return *x == 0; } </p> <p> Here is the message from the compiler: </p> <p> Invoking: GCC C++ Compiler g++ -I"/home/wolf/workspace/booster" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"booster.d" -MT"booster.d" -o"booster.o" "../booster.cpp" ../booster.cpp:15: warning: ignoring #pragma warning just ../booster.cpp:16:1: error: macro "BOOST_PP_SEQ_ELEM_III" requires 2 arguments, but only 1 given </p> <p> Note that the first call succeeds. </p> <p> Cheers </p> <p> Wolf Lammen </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4456 Trac 1.4.3 ookami1@… Sat, 24 Jul 2010 12:50:46 GMT <link>https://svn.boost.org/trac10/ticket/4456#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4456#comment:1</guid> <description> <p> Today a had a look again at fold_right.hpp to see why it failed a few days ago. To my great surprise, I was unable to reproduce the error. I do not know what has happened, but right now, everything works fine. </p> <p> I am going to mark this as invalid. </p> <p> Cheers </p> <p> Wolf Lammen </p> </description> <category>Ticket</category> </item> <item> <author>ookami1@…</author> <pubDate>Sat, 24 Jul 2010 12:51:16 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4456#comment:2 https://svn.boost.org/trac10/ticket/4456#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> Ticket