replace.pass.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <algorithm>
  10. // template<ForwardIterator Iter, class T>
  11. // requires OutputIterator<Iter, Iter::reference>
  12. // && OutputIterator<Iter, const T&>
  13. // && HasEqualTo<Iter::value_type, T>
  14. // void
  15. // replace(Iter first, Iter last, const T& old_value, const T& new_value);
  16. #include <algorithm>
  17. #include <cassert>
  18. #include "test_iterators.h"
  19. template <class Iter>
  20. void
  21. test()
  22. {
  23. int ia[] = {0, 1, 2, 3, 4};
  24. const unsigned sa = sizeof(ia)/sizeof(ia[0]);
  25. std::replace(Iter(ia), Iter(ia+sa), 2, 5);
  26. assert(ia[0] == 0);
  27. assert(ia[1] == 1);
  28. assert(ia[2] == 5);
  29. assert(ia[3] == 3);
  30. assert(ia[4] == 4);
  31. }
  32. int main()
  33. {
  34. test<forward_iterator<int*> >();
  35. test<bidirectional_iterator<int*> >();
  36. test<random_access_iterator<int*> >();
  37. test<int*>();
  38. }