lundi 3 décembre 2018

std::sort alters contents of std::array

I have an std::array<std::pair<int, int>, SIZE> Arr; I put this into std::sort as

std::array<std::pair<int, int>, SIZE> Arr;
sort(Arr.begin(), Arr.end(), std::greater<pair<int, int>>());

What's interesting is some values disappear. Normal output is :

First : 3, Second : 1
First : 3, Second : 2
First : 3, Second : 3
First : 3, Second : 4
First : 4, Second : 5
First : 2, Second : 6

And after std::sort has been called,

First : 3, Second : 4
First : 3, Second : 3
First : 3, Second : 2
First : 3, Second : 1
First : 2, Second : 6

As you might have realized Connectivity : 4, index : 5 is gone. I have no idea what's going on.

Aucun commentaire:

Enregistrer un commentaire