drop_while.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/algorithm/move.hpp>
  13. #include <range/v3/action/drop_while.hpp>
  14. #include "../simple_test.hpp"
  15. #include "../test_utils.hpp"
  16. int main()
  17. {
  18. using namespace ranges;
  19. using namespace std::placeholders;
  20. auto v = views::ints(1,21) | to<std::vector>();
  21. auto & v2 = actions::drop_while(v, std::bind(std::less<int>(), _1, 4));
  22. CHECK(&v2 == &v);
  23. CHECK(v.size() == 17u);
  24. CHECK(v[0] == 4);
  25. v = std::move(v) | actions::drop_while([](int i){return i < 7;});
  26. CHECK(v.size() == 14u);
  27. CHECK(v[0] == 7);
  28. v |= actions::drop_while([](int i){return i < 10;});
  29. CHECK(v.size() == 11u);
  30. CHECK(v[0] == 10);
  31. v |= actions::drop_while([](int){return true;});
  32. CHECK(v.size() == 0u);
  33. return ::test_result();
  34. }