Re: [Boost-users] [preporcessor]Can we use BOOST_PP_SEQ_FOLD_LEFT on sequences with one element?

________________________________________ De: boost-users-bounces@lists.boost.org [boost-users-bounces@lists.boost.org] En nombre de vicente.botet [vicente.botet@wanadoo.fr] Enviado el: jueves, 10 de julio de 2008 23:59 Para: boost-users@lists.boost.org Asunto: [Boost-users] [preporcessor]Can we use BOOST_PP_SEQ_FOLD_LEFT onsequences with one element?
Hello,
I'm a beginer with the preprocessor library. My goal is to generate from a sequence (a)(b)(c) => a::b::c and from (a) => a
[...]
BOOST_PP_SEQ_FOLD_LEFT(NAME, BOOST_PP_SEQ_HEAD((a)), BOOST_PP_SEQ_TAIL((a)))
Here lies the problem: (a) does not have a tail (there is no such thing as an empty PP sequence, unfortunately). I'm afraid you'll have to treat sequences of size 1 separately from the general case. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

----- Original Message ----- From: "JOAQUIN M. LOPEZ MUÑOZ" joaquin@tid.es ________________________________________ De: boost-users-bounces@lists.boost.org [boost-users-bounces@lists.boost.org] En nombre de vicente.botet [vicente.botet@wanadoo.fr] Asunto: [Boost-users] [preporcessor]Can we use BOOST_PP_SEQ_FOLD_LEFT onsequences with one element?
I'm a beginer with the preprocessor library. My goal is to generate from a sequence (a)(b)(c) => a::b::c and from (a) => a
[...]
BOOST_PP_SEQ_FOLD_LEFT(NAME, BOOST_PP_SEQ_HEAD((a)), BOOST_PP_SEQ_TAIL((a)))
Here lies the problem: (a) does not have a tail (there is no such thing as an empty PP sequence, unfortunately). I'm afraid you'll have to treat sequences of size 1 separately from the general case. -- Thanks Joaquin, the question now is how to treat sequences of size 1 separately from the general case. I have tried with BOOST_PP_IF, but it is no better. #include <boost/preprocessor/seq/fold_left.hpp> #include <boost/preprocessor/comparison/greater.hpp> #include <boost/preprocessor/control/if.hpp> #define XX_SIZE_GREATER_THAN_1(S) BOOST_PP_GREATER(BOOST_PP_SEQ_SIZE(S), 1) #define XX_QNAME(s, state, x) state::x #define XX_SEQ_TO_QNAME_N(S) BOOST_PP_SEQ_FOLD_LEFT(XX_QNAME \ , BOOST_PP_SEQ_HEAD(S) \ , BOOST_PP_SEQ_TAIL(S)) #define XX_SEQ_TO_QNAME_1(S) BOOST_PP_SEQ_HEAD(S) #define XX_SEQ_TO_QNAME(S) BOOST_PP_IF(XX_SIZE_GREATER_THAN_1(S)\ , XX_SEQ_TO_QNAME_N(S) \ , XX_SEQ_TO_QNAME_1(S)) XX_SEQ_TO_QNAME((a)(b)) XX_SEQ_TO_QNAME((a)) Has the following preprocessor result: a::b test.cpp:73:1: macro "BOOST_PP_SEQ_ELEM_III" requires 2 arguments, but only 1 given a And do not compile neither. Any hint? Vicente
participants (2)
-
JOAQUIN M. LOPEZ MUÑOZ
-
vicente.botet