Boost logo

Boost Users :

From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-07-11 04:56:36


----- Original Message -----
From: "JOAQUIN M. LOPEZ MUÑOZ" joaquin_at_[hidden]
________________________________________
De: boost-users-bounces_at_[hidden]
[boost-users-bounces_at_[hidden]] En nombre de vicente.botet
[vicente.botet_at_[hidden]]
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 

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net