Advertisement
Guest User

Spirit+Phoenix problem

a guest
Jul 20th, 2012
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #define BOOST_SPIRIT_USE_PHOENIX_V3 1
  2.  
  3. #include <string>
  4. #include <iostream>
  5. #include <boost/phoenix/core.hpp>
  6. #include <boost/spirit/include/qi_core.hpp>
  7. #include <boost/spirit/include/qi_lit.hpp>
  8.  
  9. namespace qi = boost::spirit::qi;
  10. namespace phoenix = boost::phoenix;
  11.  
  12. bool parse_counter_placeholder(std::string::const_iterator& it, std::string::const_iterator end, unsigned int& width)
  13. {
  14.     return qi::parse
  15.     (
  16.         it, end,
  17.         (
  18.             qi::uint_[phoenix::ref(width) = qi::_1_type()]
  19.         )
  20.     );
  21. }
  22.  
  23. int main(int argc, char* argv[])
  24. {
  25.     std::string str;
  26.     if (argc >= 2)
  27.         str = argv[1];
  28.     else
  29.         str = "5N";
  30.  
  31.     unsigned int width = 0;
  32.  
  33.     std::string::const_iterator it = str.begin();
  34.     bool res = parse_counter_placeholder(it, str.end(), width);
  35.  
  36.     std::cout << "res = " << res << ", width = " << width << std::endl;
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement