I am trying to construct a function take takes a vector, ranks it, sorts it and outputs the sorted and ranked vector with the original positioning of the values. For example: I
Here is my codes using STL to achieve this in a concise way to get the rank.
template vector calRank(const vector & var) { vector result(var.size(),0); //sorted index vector indx(var.size()); iota(indx.begin(),indx.end(),0); sort(indx.begin(),indx.end(),[&var](int i1, int i2){return var[i1]