在 std::list 中存储 boost::spirit::qi::rule

发布于 2024-10-07 02:32:22 字数 912 浏览 6 评论 0原文

我已阅读关于 boost::spirt:: 的复制或引用语义的其他线程qi::规则。我正在使用Boost 1.42。

using boost::spirit::qi::phrase_parse;
typedef boost::spirit::qi::rule < std::string::const_iterator, boost::spirit::ascii::space_type > rule_type;
std::list < rule_type > ruleList;
std::string const s("abcdef");
std::string::const_iterator iter = s.begin(), end = s.end();
std::cout << typeid(char_).name() << std::endl;
ruleList.push_back(char_);
ruleList.push_back(*ruleList.back());
assert(phrase_parse(iter, s.end(), ruleList.back(), boost::spirit::ascii::space));
assert(iter == s.end());

这会失败...

Assertion `phrase_parse(iter, s.end(), ruleList.back(), traits::space())' failed.
Aborted (core dumped)

有没有办法将规则存储在 STL 列表或双端队列中? (引用在删除之前不会消失)。

I have read the other thread about copy or reference semantics for boost::spirt::qi::rule. I am using Boost 1.42.

using boost::spirit::qi::phrase_parse;
typedef boost::spirit::qi::rule < std::string::const_iterator, boost::spirit::ascii::space_type > rule_type;
std::list < rule_type > ruleList;
std::string const s("abcdef");
std::string::const_iterator iter = s.begin(), end = s.end();
std::cout << typeid(char_).name() << std::endl;
ruleList.push_back(char_);
ruleList.push_back(*ruleList.back());
assert(phrase_parse(iter, s.end(), ruleList.back(), boost::spirit::ascii::space));
assert(iter == s.end());

This fails with...

Assertion `phrase_parse(iter, s.end(), ruleList.back(), traits::space())' failed.
Aborted (core dumped)

Is there a way to store rules in a STL list or deque? (References don't die until removed).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离不开的别离 2024-10-14 02:32:22

使用 Boost V1.45,这(本质上是上面的代码)可以正常工作(MSVC2010,g++ 4.5.1):

#include <list>
#include <string>
#include <iostream>
#include <boost/spirit/include/qi.hpp>

using namespace boost::spirit; 

int main()
{
    typedef qi::rule<std::string::const_iterator, ascii::space_type> rule_type; 
    std::list<rule_type> ruleList; 

    std::string const s("abcdef"); 
    std::string::const_iterator iter = s.begin(), end = s.end(); 
    std::cout << typeid(qi::char_).name() << std::endl; 

    ruleList.push_back(qi::char_); 
    ruleList.push_back(*ruleList.back()); 

    assert(qi::phrase_parse(iter, s.end(), ruleList.back(), ascii::space)); 
    assert(iter == s.end());

    return 0;
}

因此,我认为这是您正在使用的 Spirit 版本中的错误。

With Boost V1.45, this (essentially your code from above) works without problems (MSVC2010, g++ 4.5.1):

#include <list>
#include <string>
#include <iostream>
#include <boost/spirit/include/qi.hpp>

using namespace boost::spirit; 

int main()
{
    typedef qi::rule<std::string::const_iterator, ascii::space_type> rule_type; 
    std::list<rule_type> ruleList; 

    std::string const s("abcdef"); 
    std::string::const_iterator iter = s.begin(), end = s.end(); 
    std::cout << typeid(qi::char_).name() << std::endl; 

    ruleList.push_back(qi::char_); 
    ruleList.push_back(*ruleList.back()); 

    assert(qi::phrase_parse(iter, s.end(), ruleList.back(), ascii::space)); 
    assert(iter == s.end());

    return 0;
}

Therefore, I assume it's a bug in the version of Spirit you're using.

九歌凝 2024-10-14 02:32:22

我无法编译你的示例。除了没有使用来自...::qi的正确类型之外,您还向trait::space添加了一个() 类型。

这对我来说没有问题(boost 1.44)

#include <boost/spirit/include/qi.hpp>
#include <string>
#include <vector>
#include <cassert>

using boost::spirit::qi::phrase_parse;

typedef boost::spirit::qi::rule < std::string::const_iterator, boost::spirit::qi::space_type > rule_type;

int main() {

std::list < rule_type > ruleList;
std::string const s("abcdef");
std::string::const_iterator iter = s.begin(), end = s.end();
ruleList.push_back(*boost::spirit::qi::char_);
assert(phrase_parse(iter, s.end(), ruleList.back(), boost::spirit::qi::space));
assert(iter == s.end());

}

~>g++ test.cpp && ./a.out
~>

请注意,我使用 qi::space_type`qi::space 而不是 ascii 命名空间。我不知道 trait 命名空间是什么/在哪里。

I could not get your example to compile. Aside from not using the correct types from ...::qi, you added a () to the trait::space type.

This works w/o problem for me (boost 1.44)

#include <boost/spirit/include/qi.hpp>
#include <string>
#include <vector>
#include <cassert>

using boost::spirit::qi::phrase_parse;

typedef boost::spirit::qi::rule < std::string::const_iterator, boost::spirit::qi::space_type > rule_type;

int main() {

std::list < rule_type > ruleList;
std::string const s("abcdef");
std::string::const_iterator iter = s.begin(), end = s.end();
ruleList.push_back(*boost::spirit::qi::char_);
assert(phrase_parse(iter, s.end(), ruleList.back(), boost::spirit::qi::space));
assert(iter == s.end());

}

~>g++ test.cpp && ./a.out
~>

please note I use qi::space_type and `qi::space instead of the ascii namespace. I have no idea what/where the trait namespace is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文