I have struct like :
struct E1
{
typedef boost::tuple<
boost::optional< N::type_A >, // N - namespace
boost::optional< N::type_B >,
...................
boost::optional< N::type_X > //arbitrary number of, maximal is 7
> data_type;
// for access by name
boost::optional<N::type_A> const& type_A() const { return boost::get<0>(data); }
boost::optional<N::type_B> const& type_B() const { return boost::get<1>(data); }
.....................................
boost::optional<N::type_X> const& type_X() const { return boost::get<2>(data); }
data_type data;
};
Q: how I may create this structure using BOOST preprocessors? For me known only type_A, type_B, ..., type_X name of types.
It's need me, because I must create a lot of structures like that, only changing type_A, type_B, ... types.
In common case, can I use boost preprocessor array or set?
You could do it like this:
The
N
argument corresponds to themaNamespace
parameter. You can of course use this argument in any other way (it's just passed through verbatim), such as hardcodingN
into the macros (and passing a dummy in the argument), or encoding even the identifierdata
in there, etc.