Fill y with all the indices of x then use std::sort on y but provide a comparator that compares the corresponding elements in x:
std::vector y(x.size());
std::iota(y.begin(), y.end(), 0);
auto comparator = [&x](int a, int b){ return x[a] < x[b]; };
std::sort(y.begin(), y.end(), comparator);