tail.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Range v3 library
  2. //
  3. // Copyright Eric Niebler 2017-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 <list>
  12. #include <vector>
  13. #include <sstream>
  14. #include <range/v3/core.hpp>
  15. #include <range/v3/view/tail.hpp>
  16. #include <range/v3/view/empty.hpp>
  17. #include <range/v3/view/single.hpp>
  18. #include "../simple_test.hpp"
  19. #include "../test_utils.hpp"
  20. #include "../test_iterators.hpp"
  21. int main()
  22. {
  23. using namespace ranges;
  24. {
  25. std::vector<int> v{0,1,2,3};
  26. auto rng = views::tail(v);
  27. check_equal(rng, {1,2,3});
  28. CHECK(size(rng) == 3u);
  29. }
  30. {
  31. std::vector<int> v{};
  32. auto rng = views::tail(v);
  33. CHECK(empty(rng));
  34. CHECK(size(rng) == 0u);
  35. }
  36. {
  37. std::stringstream sin{"1 2 3 4"};
  38. istream_view<int> is(sin);
  39. auto rng = views::tail(is);
  40. check_equal(rng, {2,3,4});
  41. }
  42. {
  43. std::stringstream sin{""};
  44. istream_view<int> is(sin);
  45. auto rng = views::tail(is);
  46. CHECK(rng.begin() == rng.end());
  47. }
  48. {
  49. auto rng = views::empty<int> | views::tail;
  50. static_assert(0 == size(rng), "");
  51. CPP_assert(same_as<empty_view<int>, decltype(rng)>);
  52. }
  53. {
  54. tail_view<empty_view<int>> const rng(views::empty<int>);
  55. static_assert(0 == size(rng), "");
  56. }
  57. {
  58. auto const rng = views::single(1) | views::tail;
  59. static_assert(0 == size(rng), "");
  60. }
  61. return ::test_result();
  62. }