iota.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Range v3 library
  2. //
  3. // Copyright Eric Niebler 2014-present
  4. // Copyright Gonzalo Brito Gadeschi 2014
  5. //
  6. // Use, modification and distribution is subject to the
  7. // Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // Project home: https://github.com/ericniebler/range-v3
  12. //
  13. // Implementation based on the code in libc++
  14. // http://http://libcxx.llvm.org/
  15. //===----------------------------------------------------------------------===//
  16. //
  17. // The LLVM Compiler Infrastructure
  18. //
  19. // This file is dual licensed under the MIT and the University of Illinois Open
  20. // Source Licenses. See LICENSE.TXT for details.
  21. //
  22. //===----------------------------------------------------------------------===//
  23. #include <range/v3/core.hpp>
  24. #include <range/v3/numeric/iota.hpp>
  25. #include <range/v3/algorithm/equal.hpp>
  26. #include "../simple_test.hpp"
  27. #include "../test_iterators.hpp"
  28. template<class Iter, class Sent = Iter>
  29. void test()
  30. {
  31. int ir[] = {5, 6, 7, 8, 9};
  32. constexpr auto s = ranges::size(ir);
  33. {
  34. int ia[] = {1, 2, 3, 4, 5};
  35. ranges::iota(Iter(ia), Sent(ia + s), 5);
  36. CHECK(ranges::equal(ia, ir));
  37. }
  38. {
  39. int ia[] = {1, 2, 3, 4, 5};
  40. auto rng = ranges::make_subrange(Iter(ia), Sent(ia + s));
  41. ranges::iota(rng, 5);
  42. CHECK(ranges::equal(ia, ir));
  43. }
  44. }
  45. int main()
  46. {
  47. test<InputIterator<int*> >();
  48. test<ForwardIterator<int*> >();
  49. test<BidirectionalIterator<int*> >();
  50. test<RandomAccessIterator<int*> >();
  51. test<int*>();
  52. test<InputIterator<int*>, Sentinel<int*> >();
  53. test<ForwardIterator<int*>, Sentinel<int*> >();
  54. test<BidirectionalIterator<int*>, Sentinel<int*> >();
  55. test<RandomAccessIterator<int*>, Sentinel<int*> >();
  56. return ::test_result();
  57. }