【问题标题】:boost::spirit , How to get the "value" of a placeholderboost::spirit , 如何获得占位符的“价值”
【发布时间】:2012-12-02 18:21:42
【问题描述】:

我正在尝试构建一个解析器,它接受“/integer/(/integer/)”形式的字符串并生成一个 std::tuple 现在我有:

qi::rule<string::iterator,std::tuple<int,int>()> parser = 
      (qi::int_ >> '(' >> qi::int_ >> ')')[_val = std::make_tuple(qi::_1,qi::_2)]

由于占位符 qi::_i 的类型不正确而无法编译。如何从占位符中“提取”基础值?

【问题讨论】:

    标签: c++ boost boost-spirit


    【解决方案1】:

    Erm,你可以使用自动属性传播(又名“自动规则”):

    #include <boost/spirit/include/qi.hpp>
    #include <boost/fusion/adapted.hpp>
    #include <tuple>
    
    namespace qi = boost::spirit::qi;
    
    main( int argc, char* argv[] )
    {
        qi::rule<std::string::iterator,std::tuple<int,int>()> parser;
    
        parser = 
            (qi::int_ >> '(' >> qi::int_ >> ')')
            ;
    }
    

    注意用于将std::tuple 适配为融合序列的附加标头。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-25
      • 2012-10-03
      相关资源
      最近更新 更多