【问题标题】:Is it possible to use Boost.Spirit V2.x without Boost.Fusion?是否可以在没有 Boost.Fusion 的情况下使用 Boost.Spirit V2.x?
【发布时间】:2011-05-05 01:20:15
【问题描述】:

为了在 Boost.Spirit V2.x(尤其是 Boost.Spirit.Qi)中使用它们,真的有必要用 Boost.Fusion 包装结构/类吗?我更愿意使用语义动作来分配给成员。如果我没记错的话,这就是以前在 V1.x 中的做法...

calculator example 表明它应该仍然是可能的。到目前为止,我还没有找到一个好的方法。

我想看看你会如何在employee example 中做到这一点。以下内容无法编译,但也许有一些方法可以让它工作:

template <typename Iterator>
struct employee_parser : qi::grammar<Iterator, employee(), ascii::space_type>
{
    employee_parser() : employee_parser::base_type(start)
    {
        using qi::int_;
        using qi::lit;
        using qi::double_;
        using qi::lexeme;
        using ascii::char_;

        quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];

        start =
            lit("employee")
            >> '{'
            >>  int_[px::bind(&employee::age, qi::_val) = qi::_1] >> ','
            >>  quoted_string[px::bind(&employee::surname, qi::_val) = qi::_1] >> ','
            >>  quoted_string[px::bind(&employee::forename, qi::_val) = qi::_1] >> ','
            >>  double_[px::bind(&employee::salary, qi::_val) = qi::_1]
            >>  '}'
            ;
    }

    qi::rule<Iterator, std::string(), ascii::space_type> quoted_string;
    qi::rule<Iterator, employee(), ascii::space_type> start;
};

【问题讨论】:

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


    【解决方案1】:

    没关系,我那里还有旧的融合打印的东西。有趣的是,在您发布问题后,错误变得如此容易找到...... :)

    (既然这行得通,我肯定在生产代码中犯了另一个错误。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-16
      • 2020-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多