From: Bradley Smith (boost_at_[hidden])
Date: 2006-01-13 09:32:52


Hi everyone,

I'm new to boost but I did search the group as thoroughly as I could
before asking this. Anyway, the documentation gives this as an example:

#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp>

#define DECL(z, n, text) BOOST_PP_CAT(text, n) = n;

BOOST_PP_REPEAT_FROM_TO(5, 10, DECL, int x)
   /*
      expands to:
      int x5 = 5; int x6 = 6; int x7 = 7;
      int x8 = 8; int x9 = 9;
   */

What confuses me is that BOOST_PP_REPEAT_FROM_TO expands to BOOST_PP_CAT
and so does DECL yet after expanding DECL to BOOST_PP_CAT the (comeau)
preprocessor continues to expand BOOST_PP_CAT to give the desired
result. However, in the following code:

#define CONCAT_1(a, b) CONCAT_1_D(a, b)
#define CONCAT_1_D(a, b) a ## b
#define CONCAT_2(a, b) CONCAT_2_D(a, b)
#define CONCAT_2_D(a, b) a ## b
#define AB(c, x, y) CONCAT_ ## c(x,y)

CONCAT_1(A, B(1, p, q))

we find that we get:

CONCAT_1(p,q)

Only by changing the code to:

CONCAT_1(A, B(2, p, q)) // note the 2 rather than 1

do we get our desired result:

pq

Can someone explain what I'm not understanding here (this isn't in my
usual field of work)?

Many thanks in anticipation
Brad