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