regression_stream_eof.cpp 952 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (c) 2012 Louis Dionne
  2. // Copyright (c) 2001-2012 Hartmut Kaiser
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #include <boost/config/warning_disable.hpp>
  7. #include <boost/detail/lightweight_test.hpp>
  8. #include <boost/spirit/include/qi.hpp>
  9. #include <iostream>
  10. #include <string>
  11. struct MyInt
  12. {
  13. int i_;
  14. template <typename Istream>
  15. friend Istream operator>>(Istream& is, MyInt& self)
  16. {
  17. is >> self.i_;
  18. return is;
  19. }
  20. };
  21. int main()
  22. {
  23. using namespace boost::spirit::qi;
  24. typedef std::string::const_iterator Iterator;
  25. std::string input = "1";
  26. Iterator first(input.begin()), last(input.end());
  27. rule<Iterator, int()> my_int = stream_parser<char, MyInt>();
  28. BOOST_TEST(parse(first, last, my_int));
  29. BOOST_TEST(first == last);
  30. return boost::report_errors();
  31. }