I don't understand what is wrong with the following simple sorting code. It compiles but produce a segmentation fault when I try to run it.
I know there are other ways of doing the same kind of sorting, and the values that I'm using are all the same (so, there's nothing to sort), but I would like to understand why it produce a segmentation fault.
There is no problem if I use w[1][i]>w[1][j]
instead of w[1][i]>=w[1][j]
in the comparator.
vector<int> a(100);
iota(a.begin(),a.end(),0);
vector<vector<int> > w(2,vector<int>(100,1));
sort(a.begin(),a.end(),[&w](const int i,const int j){return w[0][i]>w[0][j] || (w[0][i]==w[0][j] && w[1][i]>=w[1][j]);});