|
Boost : |
From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2003-01-15 15:25:25
----- Original Message -----
From: "Vesa Karvonen" <vesa_karvonen_at_[hidden]>
Hi Vesa,
> The implementation of RELATION_TO_SEQ() should not be very difficult, but
> there is a quick incomplete implementation in this post, that can give
some
> ideas. A more generic "token sequence" to sequence conversion macro could
> also be very useful. Consider the following token sequences:
>
> 1 0 2 3
> B o o s t SPACE 1 3 1
>
> Neither of the above are sequences, but it would be possible to turn them
> into sequences using suitable macros (pseudo-code):
>
> TOKEN_SEQ_TO_SEQ(FIRST, REST, IS_LAST, 1 0 2 3)
> ==> (1)(0)(2)(3)
>
> TOKEN_SEQ_TO_SEQ(FIRST, REST, IS_LAST, B o o s t SPACE 1 3 1)
> ==> (B)(o)(o)(s)(t)(SPACE)(1)(3)(1)
I already have something almost exactly like this in the high-precision
arithmetic that haven't committed yet. Of course, you'd have to have a
macro for every letter of the alphabet, every number, and every
"miscellaneous" thing like "SPACE". Also, it cannot be made to work on any
operators, so you'd need special names for them too.
> BTW, the naming of SEQ_HEAD and SEQ_TAIL is, IMO, unfortunate, as they do
> not match the precedent made by LIST_FIRST and LIST_REST. IIRC, I polled
the
> group when I designed the initial list support for naming suggestions and
> FIRST/REST was the preferred choice. Even if HEAD and TAIL would, in some
> sense, be slightly better, I think that it is more important to try to be
> consistent. This is not a big issue, but it could, for instance, be useful
> for designing generic sequence manipulation macros. Actually, perhaps
there
> is a good reason to use the name SEQ_TAIL as a sequence can not be empty.
[...]
> #define SEQ2 (a,b)(c,d)(e,f)
> MAKE_SEQ(2,SEQ2)
How about this instead:
#define MAKE_SEQ(size, rel) MAKE_SEQ_D(size, rel)
#define MAKE_SEQ_D(size, rel) \
BOOST_PP_CAT( \
MAKE_SEQ_A_ ## size rel, \
0X0 \
)() \
/**/
// size 1
#define MAKE_SEQ_A_1(x) (x) MAKE_SEQ_B_1
#define MAKE_SEQ_B_1(x) (x) MAKE_SEQ_A_1
#define MAKE_SEQ_A_10X0()
#define MAKE_SEQ_B_10X0()
// size 2
#define MAKE_SEQ_A_2(x, y) ((x, y)) MAKE_SEQ_B_2
#define MAKE_SEQ_B_2(x, y) ((x, y)) MAKE_SEQ_A_2
#define MAKE_SEQ_A_20X0()
#define MAKE_SEQ_B_20x0()
// size 3
#define MAKE_SEQ_A_3(x, y, z) ((x, y, z)) MAKE_SEQ_B_3
#define MAKE_SEQ_B_3(x, y, z) ((x, y, z)) MAKE_SEQ_A_3
#define MAKE_SEQ_A_30X0()
#define MAKE_SEQ_B_30X0()
// etc.
Paul Mensonides
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk