# include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; namespace phoenix = boost::phoenix; using boost::spirit::ascii::space; using phoenix::at_c; using namespace qi::labels; typedef std::string::const_iterator Iterator; struct Data { char val; }; BOOST_FUSION_ADAPT_STRUCT(Data,(char, val)); struct TestGrammar : qi::grammar(), ascii::space_type> { qi::rule(), ascii::space_type> list; qi::rule value; TestGrammar() : TestGrammar::base_type(list) { value = qi::char_[ at_c<0>(_val) = _1 ]; list = (qi::int_ >> value)[ _val[_1] = _2 ]; } }; int main( ) { std::string input = "2 c"; Iterator iter = input.begin(), end = input.end(); TestGrammar grammar; std::map map; bool ans = phrase_parse( iter, end, grammar, space, map ); assert( ans ); assert( iter == end ); BOOST_AUTO( it, map.find(2) ); assert( it != map.end() ); assert( it->second.val == 'c' ); // FAILS! }