remove.pass.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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, RvalueOf<Iter::reference>::type>
  12. // && HasEqualTo<Iter::value_type, T>
  13. // Iter
  14. // remove(Iter first, Iter last, const T& value);
  15. #include <algorithm>
  16. #include <cassert>
  17. #ifdef _LIBCPP_MOVE
  18. #include <memory>
  19. #endif
  20. #include "../../iterators.h"
  21. template <class Iter>
  22. void
  23. test()
  24. {
  25. int ia[] = {0, 1, 2, 3, 4, 2, 3, 4, 2};
  26. const unsigned sa = sizeof(ia)/sizeof(ia[0]);
  27. Iter r = std::remove(Iter(ia), Iter(ia+sa), 2);
  28. assert(base(r) == ia + sa-3);
  29. assert(ia[0] == 0);
  30. assert(ia[1] == 1);
  31. assert(ia[2] == 3);
  32. assert(ia[3] == 4);
  33. assert(ia[4] == 3);
  34. assert(ia[5] == 4);
  35. }
  36. #ifdef _LIBCPP_MOVE
  37. template <class Iter>
  38. void
  39. test1()
  40. {
  41. const unsigned sa = 9;
  42. std::unique_ptr<int> ia[sa];
  43. ia[0].reset(new int(0));
  44. ia[1].reset(new int(1));
  45. ia[3].reset(new int(3));
  46. ia[4].reset(new int(4));
  47. ia[6].reset(new int(3));
  48. ia[7].reset(new int(4));
  49. Iter r = std::remove(Iter(ia), Iter(ia+sa), std::unique_ptr<int>());
  50. assert(base(r) == ia + sa-3);
  51. assert(*ia[0] == 0);
  52. assert(*ia[1] == 1);
  53. assert(*ia[2] == 3);
  54. assert(*ia[3] == 4);
  55. assert(*ia[4] == 3);
  56. assert(*ia[5] == 4);
  57. }
  58. #endif // _LIBCPP_MOVE
  59. int main()
  60. {
  61. test<forward_iterator<int*> >();
  62. test<bidirectional_iterator<int*> >();
  63. test<random_access_iterator<int*> >();
  64. test<int*>();
  65. #ifdef _LIBCPP_MOVE
  66. test1<forward_iterator<std::unique_ptr<int>*> >();
  67. test1<bidirectional_iterator<std::unique_ptr<int>*> >();
  68. test1<random_access_iterator<std::unique_ptr<int>*> >();
  69. test1<std::unique_ptr<int>*>();
  70. #endif // _LIBCPP_MOVE
  71. }