take_last.cpp 964 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Range v3 library
  2. //
  3. // Copyright Barry Revzin 2019-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 <range/v3/utility/copy.hpp>
  12. #include <range/v3/view/take_last.hpp>
  13. #include "../simple_test.hpp"
  14. #include "../test_utils.hpp"
  15. int main()
  16. {
  17. using namespace ranges;
  18. int rgi[] = {0, 1, 2, 3, 4, 5};
  19. auto rng0 = rgi | views::take_last(3);
  20. has_type<int &>(*begin(rng0));
  21. CPP_assert(view_<decltype(rng0)>);
  22. CPP_assert(common_range<decltype(rng0)>);
  23. CPP_assert(sized_range<decltype(rng0)>);
  24. CPP_assert(random_access_iterator<decltype(begin(rng0))>);
  25. ::check_equal(rng0, {3, 4, 5});
  26. CHECK(size(rng0) == 3u);
  27. auto rng1 = rgi | views::take_last(7);
  28. ::check_equal(rng1, {0, 1, 2, 3, 4, 5});
  29. }