]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/algorithm/example/apply_permutation_example.cpp
2 Copyright (c) Alexander Zaitsev <zamazan4ik@gmail.com>, 2017
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)
8 See http://www.boost.org/ for latest version.
14 #include <boost/algorithm/apply_permutation.hpp>
17 namespace ba
= boost::algorithm
;
19 int main ( int /*argc*/, char * /*argv*/ [] )
21 // WARNING: Example require C++11 or newer compiler
23 std::cout
<< "apply_permutation with iterators:\n";
24 std::vector
<int> vec
{1, 2, 3, 4, 5}, order
{4, 2, 3, 1, 0};
26 ba::apply_permutation(vec
.begin(), vec
.end(), order
.begin(), order
.end());
27 for (const auto& x
: vec
)
29 std::cout
<< x
<< ", ";
31 std::cout
<< std::endl
;
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};
37 ba::apply_reverse_permutation(vec
.begin(), vec
.end(), order
.begin(), order
.end());
38 for (const auto& x
: vec
)
40 std::cout
<< x
<< ", ";
42 std::cout
<< std::endl
;
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};
48 ba::apply_reverse_permutation(vec
, order
);
49 for (const auto& x
: vec
)
51 std::cout
<< x
<< ", ";
53 std::cout
<< std::endl
;
56 std::cout
<< "apply_permutation with ranges:\n";
57 std::vector
<int> vec
{1, 2, 3, 4, 5}, order
{4, 2, 3, 1, 0};
59 ba::apply_permutation(vec
, order
);
60 for (const auto& x
: vec
)
62 std::cout
<< x
<< ", ";
64 std::cout
<< std::endl
;