boost :: spirit :: qi [英] boost::spirit::qi

查看:116
本文介绍了boost :: spirit :: qi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下代码:(boost :: spirit 2.5.1)

Consider the following code: (boost::spirit 2.5.1)

qi::parse(str.begin(), str.end(), (+qi::alpha)[[](const string& s){cout << s<< '\n';}]
                                    >> (*(qi::char_(',') | qi::char_('\'')))
                                    >> qi::uint_[[](int integer){cout << integer << '\n';}]);

[[(整数){cout<<<

The "[[](int integer){cout << integer << '\n';}]" works, but the analogous code for "+qi::alpha" doesn't.

如何更正代码?

推荐答案

您的代码给我以下编译器错误,跳过一些位

Your code gives me the following compiler error, skipping some bits

/usr/include/boost/spirit/home/support/action_dispatch.hpp:142:13:
error: no matching function for call to
‘action_dispatch<>::do_call(
    const main()::<lambda(const string&)>&,
    action_dispatch<>::fwd_tag<std::vector<char>>,
...

这可以归结为传递给您的lambda的参数是向量< char> ,而不是 string

which boils down to that the argument passed to your lambda is vector<char>, not string

code> :

So, replace string with vector<char>:

(+qi::alpha)[[](const std::vector<char>& s) {
      cout << std::string(s.begin(), s.end()) << '\n';
}]

这篇关于boost :: spirit :: qi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆