Question

For instance, suppose I have the following struct/sub-struct definition:

struct address_rec
{
  std::string  m_street;
  std::string  m_state;
  unsigned     m_zip;
};

struct employee_rec
{
  std::string  m_name;
  address_rec  m_address;
};

How should I use BOOST_FUSION_ADAPT_STRUCT on employee_rec?

Was it helpful?

Solution

Adapt both structs, it also helps to break your grammars down into each struct types too, (a rule for address and a rule for employee which contains the address rule)

struct address_rec
{
  std::string  m_street;
  std::string  m_state;
  unsigned     m_zip;
};

BOOST_FUSION_ADAPT_STRUCT(
    ::address_rec,
    (std::string, m_street)
    (std::string, m_state)
    (unsigned, m_zip)
)

struct employee_rec
{
  std::string  m_name;
  address_rec  m_address;
};

BOOST_FUSION_ADAPT_STRUCT(
    ::employee_rec,
    (std::string, m_name)
    (address_rec, m_address)
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top