1

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
nkdm
  • 1,220
  • 1
  • 11
  • 26

1 Answers1

0

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

sehe
  • 374,641
  • 47
  • 450
  • 633
  • I've presented just a siplified example. I wouldn't like to retype fields in structure manually (it contains hundreds of fields and periodicially change) so I'd like to expand macros STRUCT_BEGIN and others in order to achieve adaptaion. – nkdm Feb 26 '16 at 16:36
  • I'd use my text editor features to quickly morph it into the BOOST_FUSION_DEFINE_STRUCT version. It would be seconds of work and not require me to retype anything at all. – sehe Feb 26 '16 at 16:39