fill_n.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Range v3 library
  2. //
  3. // Copyright Eric Niebler 2014
  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. //===----------------------------------------------------------------------===//
  12. //
  13. // The LLVM Compiler Infrastructure
  14. //
  15. // This file is dual licensed under the MIT and the University of Illinois Open
  16. // Source Licenses. See LICENSE.TXT for details.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #include <cstring>
  20. #include <string>
  21. #include <vector>
  22. #include <range/v3/algorithm/equal.hpp>
  23. #include <range/v3/algorithm/fill.hpp>
  24. #include <range/v3/core.hpp>
  25. #include "../array.hpp"
  26. #include "../simple_test.hpp"
  27. #include "../test_iterators.hpp"
  28. #include "../test_utils.hpp"
  29. #ifdef RANGES_CXX_GREATER_THAN_11
  30. RANGES_CXX14_CONSTEXPR auto fives()
  31. {
  32. array<int, 4> a{{0}};
  33. ranges::fill(a, 5);
  34. return a;
  35. }
  36. RANGES_CXX14_CONSTEXPR auto fives(int n)
  37. {
  38. array<int, 4> a{{0}};
  39. ranges::fill_n(ranges::begin(a), n, 5);
  40. return a;
  41. }
  42. #endif
  43. int main()
  44. {
  45. test_char<forward_iterator<char *>>();
  46. test_char<bidirectional_iterator<char *>>();
  47. test_char<random_access_iterator<char *>>();
  48. test_char<char *>();
  49. test_char<forward_iterator<char *>, sentinel<char *>>();
  50. test_char<bidirectional_iterator<char *>, sentinel<char *>>();
  51. test_char<random_access_iterator<char *>, sentinel<char *>>();
  52. test_int<forward_iterator<int *>>();
  53. test_int<bidirectional_iterator<int *>>();
  54. test_int<random_access_iterator<int *>>();
  55. test_int<int *>();
  56. test_int<forward_iterator<int *>, sentinel<int *>>();
  57. test_int<bidirectional_iterator<int *>, sentinel<int *>>();
  58. test_int<random_access_iterator<int *>, sentinel<int *>>();
  59. #ifdef RANGES_CXX_GREATER_THAN_11
  60. {
  61. STATIC_CHECK(ranges::equal(fives(), {5, 5, 5, 5}));
  62. STATIC_CHECK(ranges::equal(fives(2), {5, 5, 0, 0}));
  63. STATIC_CHECK(!ranges::equal(fives(2), {5, 5, 5, 5}));
  64. }
  65. #endif
  66. return ::test_result();
  67. }