|
Boost Users : |
Subject: Re: [Boost-users] BOOST_PP_SEQ_ENUM troubles
From: Edward Diener (eldiener_at_[hidden])
Date: 2016-07-06 19:49:07
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<x##File>}*
> *#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 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