Spirit.Qi パース結果の型

パース結果の型は、qi::ruleのattr_typeでとれるみたいです。

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

namespace qi = boost::spirit::qi;

template <class Rule, class Result>
bool parse(const std::string& s, const Rule& rule, Result& result)
{
    std::string::const_iterator first = s.begin();
    return qi::parse(first, s.end(), rule, result);
}

int main()
{
    const std::string s = "(123)";

    typedef qi::rule<std::string::const_iterator, int()> rule;

    rule::attr_type result;
    parse(s, '(' >> qi::int_ >> ')', result);

    std::cout << result << std::endl;
}
123

これで短いパース処理の際にresult_typeを用意しなくて済む。