template <class RandIter, class RandIterPerm> void permute(RandIter first, RandIter last, RandIterPerm p); template <class InIter, class RandIterP, class RandIterR> void permute_copy(InIter first, InIter last, RandIterP p, RandIterR result);
#include <iostream> #include <cassert> #include <boost/graph/detail/permutation.hpp> int main() { char array[] = "abcde"; int perm[] = { 1,3,2,4,0,5 }; char permuted_array[6]; boost::permute_copy(array, array + 6, perm, permuted_array); std::cout << "original array: " << array << std::endl; std::cout << "permuted array: " << permuted_array << std::endl; for (int i = 0; i < 5; ++i) assert(array[i] == permuted_array[perm[i]]); return EXIT_SUCCESS; }The output is:
original array: abcde permuted array: eacbd
The implementation can currently be found in a detail header of the Boost Graph Library [permutation.hpp].
Boost already has a [permutation_iterator] that provides the same functionality as the above algorithms. However, I think it would be OK to have both, since the permute() function is more convenient in some situations.