简体   繁体   中英

Adapting define/include generated struct to boost::fusion

I have a legacy structure that is defined in such a way:

// file:MyStructure_def.h
STRUCT_BEGIN
STRUCT_FIELD(int,x)
STRUCT_END
// EOF

// file: MyStructure.h
#define STRUCT_BEGIN struct MyStructure{
#define STRUCT_FIELD(a,b) a b;
#define STRUCT_END };
#include "MyStructure_def.h"
// EOF

Is it possible to adapt such a generated struct to boost::fusion with BOOST_FUSION_ADAPT_STRUCT or any other macro without retyping all fields within the structure?

How about

#include <boost/fusion/adapted/struct.hpp>

BOOST_FUSION_ADAPT_STRUCT(MyStructure,a)

For older compilers/boost versions:

BOOST_FUSION_ADAPT_STRUCT(MyStructure,(a,b))

Look also at http://www.boost.org/doc/libs/1_60_0/libs/fusion/doc/html/fusion/adapted/define_struct.html which would make your own macro redundant.

#define NONS
BOOST_FUSION_DEFINE_STRUCT(
    (NONS), MyStructure,
    (a, b))

Which defines the struct /as well as/ adapts it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM