partition_copy.pass.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 <class InputIterator, class OutputIterator1,
  11. // class OutputIterator2, class Predicate>
  12. // pair<OutputIterator1, OutputIterator2>
  13. // partition_copy(InputIterator first, InputIterator last,
  14. // OutputIterator1 out_true, OutputIterator2 out_false,
  15. // Predicate pred);
  16. #include <algorithm>
  17. #include <cassert>
  18. #include "test_iterators.h"
  19. struct is_odd
  20. {
  21. bool operator()(const int& i) const {return i & 1;}
  22. };
  23. int main()
  24. {
  25. {
  26. const int ia[] = {1, 2, 3, 4, 6, 8, 5, 7};
  27. int r1[10] = {0};
  28. int r2[10] = {0};
  29. typedef std::pair<output_iterator<int*>, int*> P;
  30. P p = std::partition_copy(input_iterator<const int*>(std::begin(ia)),
  31. input_iterator<const int*>(std::end(ia)),
  32. output_iterator<int*>(r1), r2, is_odd());
  33. assert(p.first.base() == r1 + 4);
  34. assert(r1[0] == 1);
  35. assert(r1[1] == 3);
  36. assert(r1[2] == 5);
  37. assert(r1[3] == 7);
  38. assert(p.second == r2 + 4);
  39. assert(r2[0] == 2);
  40. assert(r2[1] == 4);
  41. assert(r2[2] == 6);
  42. assert(r2[3] == 8);
  43. }
  44. }