getlines.cpp 938 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Range v3 library
  2. //
  3. // Copyright Eric Niebler 2014-present
  4. //
  5. // Use, modification and distribution is subject to the
  6. // Boost Software License, Version 1.0. (See accompanying
  7. // file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // Project home: https://github.com/ericniebler/range-v3
  11. #include <sstream>
  12. #include <range/v3/core.hpp>
  13. #include <range/v3/range/traits.hpp>
  14. #include "../simple_test.hpp"
  15. #include "../test_utils.hpp"
  16. using namespace ranges;
  17. int main()
  18. {
  19. const char* text =
  20. R"(Now is
  21. the time
  22. for all
  23. good men
  24. )";
  25. std::stringstream sin{text};
  26. auto rng = getlines(sin);
  27. ::check_equal(rng, {"Now is", "the time", "for all", "good men"});
  28. using Rng = decltype(rng);
  29. CPP_assert(input_range<Rng> && view_<Rng>);
  30. CPP_assert(!(forward_range<Rng> && view_<Rng>));
  31. CPP_assert(same_as<range_rvalue_reference_t<Rng>, std::string &&>);
  32. return ::test_result();
  33. }