delimit.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 <vector>
  12. #include <range/v3/core.hpp>
  13. #include <range/v3/view/iota.hpp>
  14. #include <range/v3/view/delimit.hpp>
  15. #include <range/v3/algorithm/for_each.hpp>
  16. #include <range/v3/utility/copy.hpp>
  17. #include "../simple_test.hpp"
  18. #include "../test_utils.hpp"
  19. int main()
  20. {
  21. using namespace ranges;
  22. auto rng0 = views::iota(10) | views::delimit(25);
  23. ::check_equal(rng0, {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24});
  24. CPP_assert(view_<decltype(rng0)>);
  25. CPP_assert(!common_range<decltype(rng0)>);
  26. CPP_assert(random_access_iterator<decltype(rng0.begin())>);
  27. CPP_assert(view_<delimit_view<views::all_t<std::vector<int> &>, int>>);
  28. CPP_assert(random_access_range<delimit_view<views::all_t<std::vector<int> &>, int>>);
  29. std::vector<int> vi{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  30. auto rng1 = vi | views::delimit(50);
  31. ::check_equal(rng1, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
  32. auto rng2 = views::delimit(vi.begin(), 8);
  33. ::check_equal(rng2, {0, 1, 2, 3, 4, 5, 6, 7});
  34. {
  35. int const some_ints[] = {1,2,3,0,4,5,6};
  36. auto rng = debug_input_view<const int>{some_ints} | views::delimit(0);
  37. ::check_equal(rng, {1,2,3});
  38. }
  39. {
  40. int const some_ints[] = {1,2,3};
  41. auto rng = views::delimit(some_ints, 0);
  42. ::check_equal(rng, {1,2,3});
  43. }
  44. return test_result();
  45. }