On 6/15/07, Arkadiy Vertleyb <vertleyb@hotmail.com > wrote:
"Server Levent Yilmaz" <leventyilmaz@gmail.com> wrote

> I have a related, simpler question:
>
> Given a tuple (or any other container) with arbitrary elements,
> is there a way to determine if an element is SPECIAL_TEXT
> or some other text.  For example given, ( a, b, SPECIAL_TEXT, c, d ),
> can we construct (0, 0, 1, 0, 0)?

If you know all the possibilities in advance, you can do something like:

#define LOOKING_FOR_SPECIAL_TEXT 1
#define LOOKING_FOR_a 0
#define LOOKING_FOR_b 0
#define LOOKING_FOR_c 0
#define LOOKING_FOR_d 0

and then transform the sequence using concatination LOOKING_FOR_ with the
current item.

Nope, I don't know in advance. In fact, those (a,b,...) are not really single character text, but rather comma separated formal arguments to a function such as (real *, const char[], etc...  ), so concat wouldnt work even if I knew the types a priori.

I did somehow come up with this dirty trick, though it doesn't quite cut it:

#include <boost/preprocessor/seq/elem.hpp>

#define SPECIAL_TYPE  ~)(1
#define IS_SPECIAL(x) BOOST_PP_SEQ_ELEM(1, (x)(0))

IS_SPECIAL( real*& )   // would give 0
IS_SPECIAL( SPECIAL_TYPE ) // would give 1

However, the whole question is not quite answered by this:

#include <boost/preprocessor/enum.hpp>
#include <boost/preprocessor/array/elem.hpp>
#include <boost/preprocessor/punctuation/paren.hpp>

#define ArgumentList1 (3, (int, real*, char[]))
#define ArgumentList2 (4, (int, real*, SPECIAL_TYPE, char[]))

#define OP(z,i,arr) IS_SPECIAL( BOOST_PP_ARRAY_ELEM(i,arr) )

( BOOST_PP_ENUM( 3, OP, ArgumentList1) ) // would give (0,0,0)
( BOOST_PP_ENUM( 4, OP, ArgumentList2) ) // obviously fails with warnings
                                         // instead of spitting (0,0,1,0)



any ideas?

Levent.

--
Server Levent Yilmaz
Mechanical Engineering
University of Pittsburgh