Hi,
I'm trying to make a macro chain that expands something like this
*A, B, C*
into something like this
*{"A", create<AFile>}, {"B", create<BFile>}, {"C", create<CFile>}*
This is what I have come up with
*#define FORMATS A, B, C // Add new formats here*
*#define SEQ_FORMATS BOOST_PP_VARIADIC_TO_SEQ(FORMATS)*
*#define ARG_PAIR(s, data, x) {#x, create
On 7/6/2016 5:27 PM, Cherotek Music wrote:
Hi, I'm trying to make a macro chain that expands something like this
*A, B, C*
into something like this
*{"A", create<AFile>}, {"B", create<BFile>}, {"C", create<CFile>}*
This is what I have come up with
*#define FORMATS A, B, C // Add new formats here* *#define SEQ_FORMATS BOOST_PP_VARIADIC_TO_SEQ(FORMATS)* *#define ARG_PAIR(s, data, x) {#x, create
}* *#define SEQ_ARG_PAIRS BOOST_PP_SEQ_TRANSFORM(ARG_PAIR, ~, SEQ_FORMATS)* *#define ARG_PAIRS BOOST_PP_SEQ_ENUM(SEQ_ARG_PAIRS)* The SEQ_ARG_PAIRS macro does expand into
*({"A", create<AFile>}) ({"B", create<BFile>}) ({"C", create<CFile>})*
but ARG_PAIRS fails with the following error:
test.cpp:20:1: error: macro "BOOST_PP_SEQ_SIZE_0" passed 2 arguments, but takes just 1 ARG_PAIRS ^ BOOST_PP_SEQ_ENUM_0 ({"B", create<BFile>}) ({"C", create<CFile>}) ({"A", create<AFile>}) ({"B", create<BFile>}) ({"C", create<CFile>})
Any ideas?
The reason for this is because after your transformation you do not have a valid seq anymore for BOOST_PP_SEQ_ENUM. Each seq element must be a one element tuple. The comma ( ',' ) in each seq element no longer makes that seq element valid, producing a two element tuple. Something like '({"A", create<AFile>})' really containes two elements of data, the first one being '{"A"' and the second one being 'create<AFile>}'.
thanks a lot
Thanks I see. I'm at work now and can't test it but would replacing the
comma in ARG_PAIR with *BOOST_PP_COMMA help?*
On Thu, Jul 7, 2016 at 1:49 AM, Edward Diener
On 7/6/2016 5:27 PM, Cherotek Music wrote:
Hi, I'm trying to make a macro chain that expands something like this
*A, B, C*
into something like this
*{"A", create<AFile>}, {"B", create<BFile>}, {"C", create<CFile>}*
This is what I have come up with
*#define FORMATS A, B, C // Add new formats here* *#define SEQ_FORMATS BOOST_PP_VARIADIC_TO_SEQ(FORMATS)* *#define ARG_PAIR(s, data, x) {#x, create
}* *#define SEQ_ARG_PAIRS BOOST_PP_SEQ_TRANSFORM(ARG_PAIR, ~, SEQ_FORMATS)* *#define ARG_PAIRS BOOST_PP_SEQ_ENUM(SEQ_ARG_PAIRS)* The SEQ_ARG_PAIRS macro does expand into
*({"A", create<AFile>}) ({"B", create<BFile>}) ({"C", create<CFile>})*
but ARG_PAIRS fails with the following error:
test.cpp:20:1: error: macro "BOOST_PP_SEQ_SIZE_0" passed 2 arguments, but takes just 1 ARG_PAIRS ^ BOOST_PP_SEQ_ENUM_0 ({"B", create<BFile>}) ({"C", create<CFile>}) ({"A", create<AFile>}) ({"B", create<BFile>}) ({"C", create<CFile>})
Any ideas?
The reason for this is because after your transformation you do not have a valid seq anymore for BOOST_PP_SEQ_ENUM. Each seq element must be a one element tuple. The comma ( ',' ) in each seq element no longer makes that seq element valid, producing a two element tuple. Something like '({"A", create<AFile>})' really containes two elements of data, the first one being '{"A"' and the second one being 'create<AFile>}'.
thanks a lot
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 7/7/2016 3:04 AM, Cherotek Music wrote:
Thanks I see. I'm at work now and can't test it but would replacing the comma in ARG_PAIR with *BOOST_PP_COMMA help?*
I do not think so.
On Thu, Jul 7, 2016 at 1:49 AM, Edward Diener
mailto:eldiener@tropicsoft.com> wrote: On 7/6/2016 5:27 PM, Cherotek Music wrote:
Hi, I'm trying to make a macro chain that expands something like this
*A, B, C*
into something like this
*{"A", create<AFile>}, {"B", create<BFile>}, {"C", create<CFile>}*
This is what I have come up with
*#define FORMATS A, B, C // Add new formats here* *#define SEQ_FORMATS BOOST_PP_VARIADIC_TO_SEQ(FORMATS)* *#define ARG_PAIR(s, data, x) {#x, create
}* *#define SEQ_ARG_PAIRS BOOST_PP_SEQ_TRANSFORM(ARG_PAIR, ~, SEQ_FORMATS)* *#define ARG_PAIRS BOOST_PP_SEQ_ENUM(SEQ_ARG_PAIRS)* The SEQ_ARG_PAIRS macro does expand into
*({"A", create<AFile>}) ({"B", create<BFile>}) ({"C", create<CFile>})*
but ARG_PAIRS fails with the following error:
test.cpp:20:1: error: macro "BOOST_PP_SEQ_SIZE_0" passed 2 arguments, but takes just 1 ARG_PAIRS ^ BOOST_PP_SEQ_ENUM_0 ({"B", create<BFile>}) ({"C", create<CFile>}) ({"A", create<AFile>}) ({"B", create<BFile>}) ({"C", create<CFile>})
Any ideas?
The reason for this is because after your transformation you do not have a valid seq anymore for BOOST_PP_SEQ_ENUM. Each seq element must be a one element tuple. The comma ( ',' ) in each seq element no longer makes that seq element valid, producing a two element tuple. Something like '({"A", create<AFile>})' really containes two elements of data, the first one being '{"A"' and the second one being 'create<AFile>}'.
thanks a lot
On 6 July 2016 at 22:27, Cherotek Music
Hi, I'm trying to make a macro chain that expands something like this
*A, B, C*
into something like this
*{"A", create<AFile>}, {"B", create<BFile>}, {"C", create<CFile>}*
This is what I have come up with
*#define FORMATS A, B, C // Add new formats here* *#define SEQ_FORMATS BOOST_PP_VARIADIC_TO_SEQ(FORMATS)* *#define ARG_PAIR(s, data, x) {#x, create
}* *#define SEQ_ARG_PAIRS BOOST_PP_SEQ_TRANSFORM(ARG_PAIR, ~, SEQ_FORMATS)* *#define ARG_PAIRS BOOST_PP_SEQ_ENUM(SEQ_ARG_PAIRS)*
Use BOOST_PP_ENUM with BOOST_PP_SEQ_SIZE and BOOST_PP_SEQ_ELEM instead of BOOST_PP_SEQ_TRANSFORM+BOOST_PP_SEQ_ENUM.
Thanks for the suggestion but I still can't get it to work :(
#define SEQ_FORMATS BOOST_PP_VARIADIC_TO_SEQ(FORMATS)
#define ARG_PAIR(x) {#x, create
On 6 July 2016 at 22:27, Cherotek Music
wrote: Hi, I'm trying to make a macro chain that expands something like this
*A, B, C*
into something like this
*{"A", create<AFile>}, {"B", create<BFile>}, {"C", create<CFile>}*
This is what I have come up with
*#define FORMATS A, B, C // Add new formats here* *#define SEQ_FORMATS BOOST_PP_VARIADIC_TO_SEQ(FORMATS)* *#define ARG_PAIR(s, data, x) {#x, create
}* *#define SEQ_ARG_PAIRS BOOST_PP_SEQ_TRANSFORM(ARG_PAIR, ~, SEQ_FORMATS)* *#define ARG_PAIRS BOOST_PP_SEQ_ENUM(SEQ_ARG_PAIRS)* Use BOOST_PP_ENUM with BOOST_PP_SEQ_SIZE and BOOST_PP_SEQ_ELEM instead of BOOST_PP_SEQ_TRANSFORM+BOOST_PP_SEQ_ENUM.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Ah I got it to work with the following:
#define SEQ_FORMATS BOOST_PP_VARIADIC_TO_SEQ(FORMATS)
#define PASTE(l,r) l##r
#define STRINGIZE(x) #x
#define ARG_PAIR(x) {STRINGIZE(x), create
Thanks for the suggestion but I still can't get it to work :(
#define SEQ_FORMATS BOOST_PP_VARIADIC_TO_SEQ(FORMATS) #define ARG_PAIR(x) {#x, create
} #define NTH_ARG(z, n, data) ARG_PAIR(BOOST_PP_SEQ_ELEM(n, data)) #define ARG_PAIRS BOOST_PP_ENUM(BOOST_PP_SEQ_SIZE(SEQ_FORMATS), NTH_ARG, SEQ_FORMATS) gives the following error:
test.h:14:63: error: pasting ")" and "File" does not give a valid preprocessing token #define NTH_ARG(z, n, data) ARG_PAIR(BOOST_PP_SEQ_ELEM(n, data)) ^ test.h:13:33: note: in definition of macro ‘ARG_PAIR’ #define ARG_PAIR(x) {#x, create
} We're getting closer though
On Thu, Jul 7, 2016 at 6:19 PM, Mathias Gaunard < mathias.gaunard@ens-lyon.org> wrote:
On 6 July 2016 at 22:27, Cherotek Music
wrote: Hi, I'm trying to make a macro chain that expands something like this
*A, B, C*
into something like this
*{"A", create<AFile>}, {"B", create<BFile>}, {"C", create<CFile>}*
This is what I have come up with
*#define FORMATS A, B, C // Add new formats here* *#define SEQ_FORMATS BOOST_PP_VARIADIC_TO_SEQ(FORMATS)* *#define ARG_PAIR(s, data, x) {#x, create
}* *#define SEQ_ARG_PAIRS BOOST_PP_SEQ_TRANSFORM(ARG_PAIR, ~, SEQ_FORMATS)* *#define ARG_PAIRS BOOST_PP_SEQ_ENUM(SEQ_ARG_PAIRS)* Use BOOST_PP_ENUM with BOOST_PP_SEQ_SIZE and BOOST_PP_SEQ_ELEM instead of BOOST_PP_SEQ_TRANSFORM+BOOST_PP_SEQ_ENUM.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 7/7/2016 6:05 PM, Cherotek Music wrote:
Ah I got it to work with the following:
#define SEQ_FORMATS BOOST_PP_VARIADIC_TO_SEQ(FORMATS) #define PASTE(l,r) l##r
BOOST_PP_CAT
#define STRINGIZE(x) #x
BOOST_PP_STRINGIZE
#define ARG_PAIR(x) {STRINGIZE(x), create
} #define NTH_ARG(z, n, data) ARG_PAIR(BOOST_PP_SEQ_ELEM(n, data)) #define ARG_PAIRS BOOST_PP_ENUM(BOOST_PP_SEQ_SIZE(SEQ_FORMATS), NTH_ARG, SEQ_FORMATS) Thanks guys!
Great !
On Thu, Jul 7, 2016 at 11:57 PM, Cherotek Music
mailto:cherotek@gmail.com> wrote: Thanks for the suggestion but I still can't get it to work :(
#define SEQ_FORMATS BOOST_PP_VARIADIC_TO_SEQ(FORMATS) #define ARG_PAIR(x) {#x, create
} #define NTH_ARG(z, n, data) ARG_PAIR(BOOST_PP_SEQ_ELEM(n, data)) #define ARG_PAIRS BOOST_PP_ENUM(BOOST_PP_SEQ_SIZE(SEQ_FORMATS), NTH_ARG, SEQ_FORMATS) gives the following error:
test.h:14:63: error: pasting ")" and "File" does not give a valid preprocessing token #define NTH_ARG(z, n, data) ARG_PAIR(BOOST_PP_SEQ_ELEM(n, data)) ^ test.h:13:33: note: in definition of macro ‘ARG_PAIR’ #define ARG_PAIR(x) {#x, create
} We're getting closer though
On Thu, Jul 7, 2016 at 6:19 PM, Mathias Gaunard
mailto:mathias.gaunard@ens-lyon.org> wrote: On 6 July 2016 at 22:27, Cherotek Music
mailto:cherotek@gmail.com> wrote: Hi, I'm trying to make a macro chain that expands something like this
*A, B, C*
into something like this
*{"A", create<AFile>}, {"B", create<BFile>}, {"C", create<CFile>}*
This is what I have come up with
*#define FORMATS A, B, C // Add new formats here* *#define SEQ_FORMATS BOOST_PP_VARIADIC_TO_SEQ(FORMATS)* *#define ARG_PAIR(s, data, x) {#x, create
}* *#define SEQ_ARG_PAIRS BOOST_PP_SEQ_TRANSFORM(ARG_PAIR, ~, SEQ_FORMATS)* *#define ARG_PAIRS BOOST_PP_SEQ_ENUM(SEQ_ARG_PAIRS)* Use BOOST_PP_ENUM with BOOST_PP_SEQ_SIZE and BOOST_PP_SEQ_ELEM instead of BOOST_PP_SEQ_TRANSFORM+BOOST_PP_SEQ_ENUM.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org mailto:Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Cherotek Music
-
Edward Diener
-
Mathias Gaunard