partition_move.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. // Copyright 2005 - 2007 Adobe Systems Incorporated
  13. // Distributed under the MIT License(see accompanying file LICENSE_1_0_0.txt
  14. // or a copy at http://stlab.adobe.com/licenses.html)
  15. //===----------------------------------------------------------------------===//
  16. //
  17. // The LLVM Compiler Infrastructure
  18. //
  19. // This file is dual licensed under the MIT and the University of Illinois Open
  20. // Source Licenses. See LICENSE.TXT for details.
  21. //
  22. //===----------------------------------------------------------------------===//
  23. #include <tuple>
  24. #include <range/v3/algorithm/partition_move.hpp>
  25. #include <range/v3/core.hpp>
  26. #include "../simple_test.hpp"
  27. struct is_odd
  28. {
  29. constexpr bool operator()(const int & i) const
  30. {
  31. return i & 1;
  32. }
  33. };
  34. constexpr bool test_constexpr()
  35. {
  36. using namespace ranges;
  37. const int ia[] = {1, 2, 3, 4, 6, 8, 5, 7};
  38. int r1[10] = {0};
  39. int r2[10] = {0};
  40. typedef std::tuple<int const *, int *, int *> P;
  41. P p = partition_move(ia, r1, r2, is_odd());
  42. STATIC_CHECK_RETURN(std::get<0>(p) == std::end(ia));
  43. STATIC_CHECK_RETURN(std::get<1>(p) == r1 + 4);
  44. STATIC_CHECK_RETURN(r1[0] == 1);
  45. STATIC_CHECK_RETURN(r1[1] == 3);
  46. STATIC_CHECK_RETURN(r1[2] == 5);
  47. STATIC_CHECK_RETURN(r1[3] == 7);
  48. STATIC_CHECK_RETURN(std::get<2>(p) == r2 + 4);
  49. STATIC_CHECK_RETURN(r2[0] == 2);
  50. STATIC_CHECK_RETURN(r2[1] == 4);
  51. STATIC_CHECK_RETURN(r2[2] == 6);
  52. STATIC_CHECK_RETURN(r2[3] == 8);
  53. return true;
  54. }
  55. int main()
  56. {
  57. {
  58. STATIC_CHECK(test_constexpr());
  59. }
  60. return ::test_result();
  61. }