apply_permutation_example.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. Copyright (c) Alexander Zaitsev <zamazan4ik@gmail.com>, 2017
  3. Distributed under the Boost Software License, Version 1.0. (See
  4. accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. See http://www.boost.org/ for latest version.
  7. */
  8. #include <vector>
  9. #include <iostream>
  10. #include <boost/algorithm/apply_permutation.hpp>
  11. namespace ba = boost::algorithm;
  12. int main ( int /*argc*/, char * /*argv*/ [] )
  13. {
  14. // WARNING: Example require C++11 or newer compiler
  15. {
  16. std::cout << "apply_permutation with iterators:\n";
  17. std::vector<int> vec{1, 2, 3, 4, 5}, order{4, 2, 3, 1, 0};
  18. ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
  19. for (const auto& x : vec)
  20. {
  21. std::cout << x << ", ";
  22. }
  23. std::cout << std::endl;
  24. }
  25. {
  26. std::cout << "apply_reverse_permutation with iterators:\n";
  27. std::vector<int> vec{1, 2, 3, 4, 5}, order{4, 2, 3, 1, 0};
  28. ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
  29. for (const auto& x : vec)
  30. {
  31. std::cout << x << ", ";
  32. }
  33. std::cout << std::endl;
  34. }
  35. {
  36. std::cout << "apply_reverse_permutation with ranges:\n";
  37. std::vector<int> vec{1, 2, 3, 4, 5}, order{4, 2, 3, 1, 0};
  38. ba::apply_reverse_permutation(vec, order);
  39. for (const auto& x : vec)
  40. {
  41. std::cout << x << ", ";
  42. }
  43. std::cout << std::endl;
  44. }
  45. {
  46. std::cout << "apply_permutation with ranges:\n";
  47. std::vector<int> vec{1, 2, 3, 4, 5}, order{4, 2, 3, 1, 0};
  48. ba::apply_permutation(vec, order);
  49. for (const auto& x : vec)
  50. {
  51. std::cout << x << ", ";
  52. }
  53. std::cout << std::endl;
  54. }
  55. return 0;
  56. }