Boost logo

Boost Users :

From: Eric Robert (synapzzz_at_[hidden])
Date: 2003-09-23 12:00:32


Hi,
Maybe somebody can help me here. I'm just trying to understand what's going
on with the FOR code. It goes something like this (I expanded the general
include and stripped some code for clarity) :

# define BOOST_PP_FOR BOOST_PP_CAT(BOOST_PP_FOR_,
BOOST_PP_AUTO_REC(BOOST_PP_FOR_P, 256))
#
# define BOOST_PP_FOR_P(n) BOOST_PP_CAT(BOOST_PP_FOR_CHECK_, BOOST_PP_FOR_
## n(1, BOOST_PP_FOR_SR_P, BOOST_PP_FOR_SR_O, BOOST_PP_FOR_SR_M))
#
# define BOOST_PP_FOR_SR_P(r, s) s
# define BOOST_PP_FOR_SR_O(r, s) 0
# define BOOST_PP_FOR_SR_M(r, s) BOOST_PP_NIL
#
# define BOOST_PP_FOR_1(s, p, o, m) BOOST_PP_FOR_1_C(BOOST_PP_BOOL(p(2, s)),
s, p, o, m)
# define BOOST_PP_FOR_2(s, p, o, m) BOOST_PP_FOR_2_C(BOOST_PP_BOOL(p(3, s)),
s, p, o, m)
# define BOOST_PP_FOR_3(s, p, o, m) BOOST_PP_FOR_3_C(BOOST_PP_BOOL(p(4, s)),
s, p, o, m)
# define BOOST_PP_FOR_4(s, p, o, m) BOOST_PP_FOR_4_C(BOOST_PP_BOOL(p(5, s)),
s, p, o, m)
# define BOOST_PP_FOR_5(s, p, o, m) BOOST_PP_FOR_5_C(BOOST_PP_BOOL(p(6, s)),
s, p, o, m)
#
# //
# // EXTENDED include <boost/preprocessor/repetition/detail/for.hpp>
#
# define BOOST_PP_FOR_1(s, p, o, m) BOOST_PP_FOR_1_C(BOOST_PP_BOOL(p(2,
s)), s, p, o, m)
# define BOOST_PP_FOR_2(s, p, o, m) BOOST_PP_FOR_2_C(BOOST_PP_BOOL(p(3,
s)), s, p, o, m)
# define BOOST_PP_FOR_3(s, p, o, m) BOOST_PP_FOR_3_C(BOOST_PP_BOOL(p(4,
s)), s, p, o, m)
# define BOOST_PP_FOR_4(s, p, o, m) BOOST_PP_FOR_4_C(BOOST_PP_BOOL(p(5,
s)), s, p, o, m)
# define BOOST_PP_FOR_5(s, p, o, m) BOOST_PP_FOR_5_C(BOOST_PP_BOOL(p(6,
s)), s, p, o, m)
#
# define BOOST_PP_FOR_1_C(c, s, p, o, m) BOOST_PP_IIF(c, m,
BOOST_PP_TUPLE_EAT_2)(2, s) BOOST_PP_IIF(c, BOOST_PP_FOR_2,
BOOST_PP_TUPLE_EAT_4)(BOOST_PP_EXPR_IIF(c, o)(2, s), p, o, m)
# define BOOST_PP_FOR_2_C(c, s, p, o, m) BOOST_PP_IIF(c, m,
BOOST_PP_TUPLE_EAT_2)(3, s) BOOST_PP_IIF(c, BOOST_PP_FOR_3,
BOOST_PP_TUPLE_EAT_4)(BOOST_PP_EXPR_IIF(c, o)(3, s), p, o, m)
# define BOOST_PP_FOR_3_C(c, s, p, o, m) BOOST_PP_IIF(c, m,
BOOST_PP_TUPLE_EAT_2)(4, s) BOOST_PP_IIF(c, BOOST_PP_FOR_4,
BOOST_PP_TUPLE_EAT_4)(BOOST_PP_EXPR_IIF(c, o)(4, s), p, o, m)
# define BOOST_PP_FOR_4_C(c, s, p, o, m) BOOST_PP_IIF(c, m,
BOOST_PP_TUPLE_EAT_2)(5, s) BOOST_PP_IIF(c, BOOST_PP_FOR_5,
BOOST_PP_TUPLE_EAT_4)(BOOST_PP_EXPR_IIF(c, o)(5, s), p, o, m)
# define BOOST_PP_FOR_5_C(c, s, p, o, m) BOOST_PP_IIF(c, m,
BOOST_PP_TUPLE_EAT_2)(6, s) BOOST_PP_IIF(c, BOOST_PP_FOR_6,
BOOST_PP_TUPLE_EAT_4)(BOOST_PP_EXPR_IIF(c, o)(6, s), p, o, m)
#
# define BOOST_PP_FOR_257(s, p, o, m) BOOST_PP_ERROR(0x0002)
#
# define BOOST_PP_FOR_CHECK_BOOST_PP_NIL 1
#
# define BOOST_PP_FOR_CHECK_BOOST_PP_FOR_1(s, p, o, m) 0
# define BOOST_PP_FOR_CHECK_BOOST_PP_FOR_2(s, p, o, m) 0
# define BOOST_PP_FOR_CHECK_BOOST_PP_FOR_3(s, p, o, m) 0
# define BOOST_PP_FOR_CHECK_BOOST_PP_FOR_4(s, p, o, m) 0
# define BOOST_PP_FOR_CHECK_BOOST_PP_FOR_5(s, p, o, m) 0

Now, I'm trying to understand how it works. I don't understand why FOR isn't
a shortcut for FOR_1. The only reason I see is the FOR_CHECK test but I
can't seems to understand how it works.

Anyone ?

Eric Robert


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