fill.pass.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <algorithm>
  10. // template<ForwardIterator Iter, class T>
  11. // requires OutputIterator<Iter, const T&>
  12. // void
  13. // fill(Iter first, Iter last, const T& value);
  14. #include <algorithm>
  15. #include <cassert>
  16. #include "../../iterators.h"
  17. template <class Iter>
  18. void
  19. test_char()
  20. {
  21. const unsigned n = 4;
  22. char ca[n] = {0};
  23. std::fill(Iter(ca), Iter(ca+n), char(1));
  24. assert(ca[0] == 1);
  25. assert(ca[1] == 1);
  26. assert(ca[2] == 1);
  27. assert(ca[3] == 1);
  28. }
  29. template <class Iter>
  30. void
  31. test_int()
  32. {
  33. const unsigned n = 4;
  34. int ia[n] = {0};
  35. std::fill(Iter(ia), Iter(ia+n), 1);
  36. assert(ia[0] == 1);
  37. assert(ia[1] == 1);
  38. assert(ia[2] == 1);
  39. assert(ia[3] == 1);
  40. }
  41. int main()
  42. {
  43. test_char<forward_iterator<char*> >();
  44. test_char<bidirectional_iterator<char*> >();
  45. test_char<random_access_iterator<char*> >();
  46. test_char<char*>();
  47. test_int<forward_iterator<int*> >();
  48. test_int<bidirectional_iterator<int*> >();
  49. test_int<random_access_iterator<int*> >();
  50. test_int<int*>();
  51. }