1

im confused with boost Spirit X3 and string_ref class. How to construct a string_ref object. The console prints somethink like this :

N5boost16basic_string_refIcSt11char_traitsIcEEE / N5boost14iterator_rangeIN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEEE

I dont know how to translate it to "normal type name" but it seems to me that i need to create the string_ref from a boost iterator range ?

 auto f = [](auto& ctx)
    { 
        auto val  = _val(ctx);
        auto attr = _attr(ctx);

        std::cout << typeid(val).name() << " / " << typeid(attr).name() << "\n";
        // _val(ctx) = boost::string_ref( attr.c_str(), 1 ); //phx::construct<boost::string_ref>( _where(ctx).begin(), _attr(ctx).size() );
     };

And the rule is :

  auto const quote  = rule<struct quote, Type>{"quote"} 
                    =    lit('"')
                     >> raw[*~char_('"')][ f ]
                     >> lit('"');
4

1 回答 1

2

在发表评论后,cv_and_he我使用以下 lambda 作为语义操作

auto f = [](auto& ctx)
{ 
    auto& attr = _attr(ctx);
    _val(ctx) = boost::string_ref( &attr[0], attr.size() );
};
于 2016-02-25T16:00:25.350 回答