I got a vector containing pairs. My pairs have template parameters.
std::vector<std::pair<T1, T2> > myVector;
I would like to sort myVector by the pairs second data tag, so by the "value"(T2), not the "key"(T1). I saw here that i can use this sweet method:
std::sort(myVector.begin(), myVector.end(), mySortingFunc);
and this is my sortFunc:
bool mySortingFunc (std::pair<T1, T2> pair1, std::pair<T1, T2> pair2){
return (pair1.second<pair2.second);
}
and its not compiling, throwing me 10 kilometers long error. (i use g++) Any advice how should i do this?
- E D I T:
Actual code:
template<typename T1, typename T2>
class OrderedMMap
{
std::vector<std::pair<T1, T2> > myVector;
public:
bool sortFunc (std::pair<T1, T2> pair1, std::pair<T1, T2> pair2) {
return (pair1.second<pair2.second);
}
void sortIt()
{
std::sort(myVector.begin(), myVector.end(), sortFunc);
}
};
<operator implemented?T2? Doesoperator<exist for this type?