#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
 
typedef unsigned int uint;
 
enum {ASCEND, DESCEND};
 
template<typename T>
bool ascend_sort(pair<uint, T> i, pair<uint, T> j){return j.second>i.second;}
 
template<typename T>
bool descend_sort(pair<uint, T> i, pair<uint, T> j){return i.second>j.second;}
 
template<typename T>
void sortIdx(vector<uint>& idx, const vector<T>& src, int dir=ASCEND){
    vector< pair<uint, T>  > tmp (src.size());
    for (uint i=0; i<src.size(); i++){
        tmp.push_back(pair<uint, T>(i, src[i]));
        cout << i << " " << src[i] << " \n";
    }
 
    if (dir==ASCEND){
        sort(tmp.begin(), tmp.end(), ascend_sort<T>);
    }else{
        sort(tmp.begin(), tmp.end(), descend_sort<T>);
    }
 
    idx.resize(src.size());
 
    for (uint i=0; i<src.size(); i++){
        idx[i] = (tmp[i].first);
        cout << tmp[i].first << " \n" ;
    }
}
 
int main(){
        
        vector<float> src;
        src.push_back(3.0f);
        src.push_back(2.0f);
        src.push_back(4.0f);
        
        vector<uint> tmp;       
 
        sortIdx(tmp, src);
}