Boost logo

Boost Users :

From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2006-08-03 06:57:27


> -----Original Message-----
> From: boost-users-bounces_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of
> Roman Perepelitsa

> I have implemented macro which converts SEQ to ((a, b)) ((c,
> d)) but implementation is huge (I copy-pasted a lot of code
> from boost.preprocessor).
> Now I need to enumerate sequence of triples and I don't want
> to copy-paste again.
>
> Any tips?

#include <boost/preprocessor/cat.hpp>

#define BINARY_SEQ_TO_SEQ(seq) \
    BOOST_PP_CAT(BINARY_SEQ_TO_SEQ_A seq, 0) \
    /**/

#define BINARY_SEQ_TO_SEQ_A(x, y) ((x, y)) BINARY_SEQ_TO_SEQ_B
#define BINARY_SEQ_TO_SEQ_B(x, y) ((x, y)) BINARY_SEQ_TO_SEQ_A
#define BINARY_SEQ_TO_SEQ_A0
#define BINARY_SEQ_TO_SEQ_B0

BINARY_SEQ_TO_SEQ( (a, b)(c, d)(e, f) )
  // ((a, b))((c, d))((e, f))

#define TERNARY_SEQ_TO_SEQ(seq) \
    BOOST_PP_CAT(TERNARY_SEQ_TO_SEQ_A seq, 0) \
    /**/

#define TERNARY_SEQ_TO_SEQ_A(x, y, z) ((x, y, z)) TERNARY_SEQ_TO_SEQ_B
#define TERNARY_SEQ_TO_SEQ_B(x, y, z) ((x, y, z)) TERNARY_SEQ_TO_SEQ_A
#define TERNARY_SEQ_TO_SEQ_A0
#define TERNARY_SEQ_TO_SEQ_B0

TERNARY_SEQ_TO_SEQ( (a, b, c)(d, e, f)(g, h, i) )
  // ((a, b, c))((d, e, f))((g, h, i))

Regards,
Paul Mensonides


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