7 template <
typename T,
typename Compare>
8 void getSortPermutation(
9 std::vector<unsigned>& out,
10 const std::vector<T>& v,
11 Compare compare = std::less<T>())
14 std::iota(out.begin(), out.end(), 0);
16 std::sort(out.begin(), out.end(),
17 [&](
unsigned i,
unsigned j){
return compare(v[i], v[j]); });
21 void applyPermutation(
22 const std::vector<unsigned>& order,
25 assert(order.size() == t.size());
26 std::vector<T> st(t.size());
27 for(
unsigned i=0; i<t.size(); i++)
34 template <
typename T,
typename... S>
35 void applyPermutation(
36 const std::vector<unsigned>& order,
40 applyPermutation(order, t);
41 applyPermutation(order, s...);
44 template<
typename T,
typename Compare,
typename... SS>
46 const std::vector<T>& t,
48 std::vector<SS>&... ss)
50 std::vector<unsigned> order;
51 getSortPermutation(order, t, comp);
52 applyPermutation(order, ss...);
56 template<
typename T,
typename... SS>
57 void sortVectorsAscending(
58 const std::vector<T>& t,
59 std::vector<SS>&... ss)
61 sortVectors(t, std::less<T>(), ss...);