创建一个凤凰函数用于灵魂统治

Create a phoenix function for use in spirit rule

本文关键字:用于 函数 灵魂 凤凰 一个 创建      更新时间:2023-10-16

我试图使下面的代码编译,但是,像往常一样,spirit/phoenix的错误给出了很多关于什么是错误的线索。谁知道是什么问题吗?

#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/shared_ptr.hpp>

typedef boost::shared_ptr<int> sptr;

struct bar
{
    template <typename A> struct result
    {
        typedef sptr type;
    };
    template <typename A> sptr operator()(A) const
    {
        return sptr();
    }
};

boost::phoenix::function<bar> foo;

void test()
{
    namespace qi = boost::spirit::qi;
    using qi::_val;
    qi::rule
    <
        std::string::const_iterator,
        sptr(),
        boost::spirit::ascii::space_type
    >
        test_rule = qi::eps [ _val = foo() ];
}

正如ildjarn所说,调用foo会遗漏一个参数。