#include <iostream>
#include <vector>
#include <functional>
#include <iomanip>
#include <valarray>
int main()
{
{
std::vector<int> seq { 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65 } ;
for( int v : seq ) std::cout << v << ' ' ;
std::cout << " (values)\n" ;
for( std::size_t pos = 0 ; pos < seq.size() ; ++pos )
std::cout << std::setw(2) << pos << ' ' ;
std::cout << " (original order)\n" ; ;
std::vector<std::size_t> order { 1, 9, 5, 7, 11, 2, 3, 8, 4, 6, 0, 10 } ;
for( std::size_t pos : order ) std::cout << std::setw(2) << pos << ' ' ;
std::cout << " (required order)\n" ; ;
std::vector< std::reference_wrapper<int> > indirect ;
for(std::size_t pos : order ) indirect.emplace_back( seq[pos] ) ;
for( int v : indirect ) std::cout << v << ' ' ;
std::cout << " (indirect)\n" ; ;
}
{
std::valarray<int> seq { 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65 } ;
std::valarray<std::size_t> order { 1, 9, 5, 7, 11, 2, 3, 8, 4, 6, 0, 10 } ;
std::valarray<int> indirect { seq[order] } ;
for( int v : indirect ) std::cout << v << ' ' ;
std::cout << " (indirect)\n" ; ;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPGlvbWFuaXA+CiNpbmNsdWRlIDx2YWxhcnJheT4KCmludCBtYWluKCkKewogICAgewogICAgICAgIHN0ZDo6dmVjdG9yPGludD4gc2VxIHsgMTAsIDE1LCAyMCwgMjUsIDMwLCAzNSwgNDAsIDQ1LCA1MCwgNTUsIDYwLCA2NSB9IDsKICAgICAgICBmb3IoIGludCB2IDogc2VxICkgc3RkOjpjb3V0IDw8IHYgPDwgJyAnIDsKICAgICAgICBzdGQ6OmNvdXQgPDwgIiAodmFsdWVzKVxuIiA7CgogICAgICAgIGZvciggc3RkOjpzaXplX3QgcG9zID0gMCA7IHBvcyA8IHNlcS5zaXplKCkgOyArK3B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