[preprocessor] Enumerating sequence of pairs
Hello. I want to enumerate sequence of pairs but can't figure out how to do it using boost.preprocessor. Here is example. // sequence of pairs #define SEQ (a, b) (c, d) // How can I implement this macro? #define MAGIC(S) ... MAGIC(SEQ) expands to abcd. If I had possibility to convert SEQ to ((a, b)) ((c, d)) problem would be solved easily because it's standard sequence and thus can be enumerated using with BOOST_PP_SEQ_FOLD_LEFT or another boost.preprocessor algorithm. 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? Roman Perepelitsa.
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] 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
Paul Mensonides <pmenso57 <at> comcast.net> writes:
... BINARY_SEQ_TO_SEQ( (a, b)(c, d)(e, f) ) // ((a, b))((c, d))((e, f)) ... 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
Awesome! Thank you very much! Roman Perepelitsa.
participants (2)
-
Paul Mensonides
-
Roman Perepelitsa