regression_iterator.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2013 Louis Dionne
  2. // Copyright (c) 2001-2013 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/range/adaptor/transformed.hpp>
  9. #include <boost/spirit/include/karma.hpp>
  10. #include <iostream>
  11. // Note how the return is made by value instead of by reference.
  12. template <typename T> T identity(T const& t) { return t; }
  13. template <typename Char, typename Expr, typename CopyExpr, typename CopyAttr
  14. , typename Delimiter, typename Attribute>
  15. bool test(Char const *expected,
  16. boost::spirit::karma::detail::format_manip<
  17. Expr, CopyExpr, CopyAttr, Delimiter, Attribute> const& fm)
  18. {
  19. std::ostringstream ostrm;
  20. ostrm << fm;
  21. return ostrm.good() && ostrm.str() == expected;
  22. }
  23. int main()
  24. {
  25. namespace karma = boost::spirit::karma;
  26. namespace adaptors = boost::adaptors;
  27. int ints[] = {0, 1, 2, 3, 4};
  28. BOOST_TEST((test("0 1 2 3 4",
  29. karma::format(karma::int_ % ' ',
  30. ints | adaptors::transformed(&identity<int>)))
  31. ));
  32. return boost::report_errors();
  33. }