drop.cpp 900 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. #include <vector>
  10. #include <range/v3/core.hpp>
  11. #include <range/v3/view/iota.hpp>
  12. #include <range/v3/action/drop.hpp>
  13. #include "../simple_test.hpp"
  14. #include "../test_utils.hpp"
  15. int main()
  16. {
  17. using namespace ranges;
  18. auto v = views::ints(1,21) | to<std::vector>();
  19. auto & v2 = actions::drop(v, 3);
  20. CHECK(&v2 == &v);
  21. CHECK(v.size() == 17u);
  22. CHECK(v[0] == 4);
  23. v = std::move(v) | actions::drop(3);
  24. CHECK(v.size() == 14u);
  25. CHECK(v[0] == 7);
  26. v |= actions::drop(3);
  27. CHECK(v.size() == 11u);
  28. CHECK(v[0] == 10);
  29. v |= actions::drop(100);
  30. CHECK(v.size() == 0u);
  31. return ::test_result();
  32. }