我不是很確定爲什麼下面的代碼在GCC 4.6.3中給我下面的錯誤:如何在boost :: spirit語義動作中將函數對象的結果賦值給本地
' operator ='in'boost :: spirit :: _ a = boost :: phoenix :: function :: operator()(const A0 &)const [with A0 = boost :: phoenix :: actor>,F = make_line_impl,typename boost :: phoenix :: as_composite,F,A0> :: type = boost :: phoenix :: composite,boost :: fusion :: vector,boost :: spirit :: argument < 0>,boost :: fusion :: void_, boost :: fusion :: void_,boost :: fusion :: void_,boost :: fusion :: void_,boost :: fusion :: void_,boost :: fusion :: void_,boost :: fusion :: void_,boost: :fusion :: void_ >>>((* & boost :: spirit :: _ 1))'
它甚至可以將一個惰性函數對象的結果賦給一個qi佔位符?
#include <string>
#include <boost/spirit/include/phoenix_function.hpp>
#include <boost/spirit/include/qi.hpp>
using std::string;
using boost::spirit::qi::grammar;
using boost::spirit::qi::rule;
using boost::spirit::qi::space_type;
using boost::spirit::qi::skip_flag;
using boost::spirit::unused_type;
namespace qi = boost::spirit::qi;
namespace phx = boost::phoenix;
struct make_line_impl
{
int* _context;
make_line_impl(int* context)
{
_context = context;
}
template <typename Sig>
struct result;
template <typename This, typename Arg>
struct result<This(Arg const &)>
{
typedef int* type;
};
template <typename Arg>
int* operator()(Arg const & content)
{
return new int(5);
}
};
template<typename Iterator>
struct MyGrammar : grammar<Iterator, unused_type, space_type>
{
rule<Iterator, unused_type, space_type> start;
rule<Iterator, int*(), space_type> label;
rule<Iterator, string*(), qi::locals<int*>, space_type> line;
MyGrammar() : MyGrammar::base_type(start)
{
make_line_impl mlei(new int(5));
phx::function<make_line_impl> make_line(mlei);
start = *(line);
line = label[qi::_a = make_line(qi::_1)];
}
};
int main(int argc, char **argv) {
string contents;
qi::phrase_parse(contents.begin(), contents.end(), MyGrammar<string::iterator>(), space_type(), skip_flag::postskip);
return 0;
}