I am trying to sort vector of pair of pair and int as below. But not getting expected output. In the actual output, the last element is supposed to come before the second element.Can someone please explain what i am missing?
int main()
{
using elem_type = std::pair<std::pair<int,int>,int>;
std::vector<elem_type> vec;
vec.push_back(std::make_pair(std::make_pair(3, 1), 2));
vec.push_back(std::make_pair(std::make_pair(6, 5), 4));
vec.push_back(std::make_pair(std::make_pair(6, 4), 7));
vec.push_back(std::make_pair(std::make_pair(5, 4), 6));
auto cmp = [](const elem_type & left, const elem_type & right){
return ((left.first.first< right.first.first)
&&
(left.first.second < right.first.second));
};
std::sort(vec.begin(), vec.end(), cmp);
//print sorted vector
for(size_t i = 0; i < vec.size(); ++i){
std::cout << vec[i].first.first << " " << vec[i].first.second << " " << vec[i].second << "\n";
}
}
Expected output
3 1 2
5 4 6
6 4 7
6 5 4
Actual output
3 1 2
6 5 4
6 4 7
5 4 6