如何将BOOST_FUSION_ADAPT_STRUCT与子结构一起使用?

时间:2012-11-26 13:15:08

标签: c++ boost-spirit boost-fusion

例如,假设我有以下结构/子结构定义:

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

1 个答案:

答案 0 :(得分:6)

调整两个结构,它也有助于将语法分解为每个结构类型,(地址规则和包含地址规则的员工规则)

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)
)