stride.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 <array>
  10. #include <vector>
  11. #include <range/v3/core.hpp>
  12. #include <range/v3/view/iota.hpp>
  13. #include <range/v3/algorithm/copy.hpp>
  14. #include <range/v3/algorithm/move.hpp>
  15. #include <range/v3/algorithm/equal.hpp>
  16. #include <range/v3/action/stride.hpp>
  17. #include "../simple_test.hpp"
  18. #include "../test_utils.hpp"
  19. int main()
  20. {
  21. using namespace ranges;
  22. auto v = views::ints(0,100) | to<std::vector>();
  23. auto v2 = v | copy | actions::stride(10);
  24. CHECK(size(v2) == 10u);
  25. CPP_assert(same_as<decltype(v), decltype(v2)>);
  26. ::check_equal(v2, {0,10,20,30,40,50,60,70,80,90});
  27. v2 = v2 | move | actions::stride(4);
  28. ::check_equal(v2, {0,40,80});
  29. v2 |= actions::stride(2);
  30. ::check_equal(v2, {0,80});
  31. v2 |= actions::stride(1);
  32. ::check_equal(v2, {0,80});
  33. v2 |= actions::stride(10);
  34. ::check_equal(v2, {0});
  35. auto & v3 = actions::stride(v, 30);
  36. CHECK(&v3 == &v);
  37. ::check_equal(v, {0,30,60,90});
  38. return ::test_result();
  39. }