reverse.cpp 950 B

1234567891011121314151617181920212223242526272829303132333435
  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. #include <vector>
  10. #include <range/v3/core.hpp>
  11. #include <range/v3/view/iota.hpp>
  12. #include <range/v3/view/repeat_n.hpp>
  13. #include <range/v3/view/for_each.hpp>
  14. #include <range/v3/action/reverse.hpp>
  15. #include <range/v3/action/unique.hpp>
  16. #include "../simple_test.hpp"
  17. #include "../test_utils.hpp"
  18. using namespace ranges;
  19. int main()
  20. {
  21. // [1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,...]
  22. auto v =
  23. views::for_each(views::ints(1,6), [](int i){
  24. return yield_from(views::repeat_n(i,i));
  25. }) | to<std::vector>();
  26. check_equal(v, {1,2,2,3,3,3,4,4,4,4,5,5,5,5,5});
  27. v |= actions::unique | actions::reverse;
  28. check_equal(v, {5,4,3,2,1});
  29. return ::test_result();
  30. }