Comment 7 for bug 600267

Revision history for this message
Fernando Lucchesi (fernandolbastos) wrote :

Interesting, I didn't know boost, it seems to be quite useful.

I agree we usually shouldn't use custom sort routines, but it seems to be one of the best solutions to this specific problem(as the vectors are small and there's no standard way of sorting two separate vectors at once).

I've searched the web to see if anyone had already done anything like that using boost. However, there seems to be no easy way to use boost iterator with std::sort:
http://boost.2283326.n4.nabble.com/iterator-std-sort-on-zip-iterator-td2659322.html

There is a way, but IMHO it wouldn't really increase readability, and has even more chances of having bugs:
http://www.stanford.edu/~dgleich/notebook/2006/03/sorting_two_arrays_simultaneou.html

Another option would be to, instead of using boost, make a custom vector class(of pairs, maybe), only so that std::sort could correctly "view" the two vectors as a single thing. This class would have pointers to the original vectors(instead of a copy of its contents), and we would overload its access operator([]) to use directly the values on the original vectors. I'm not sure if it would work "as is", but I'll play with this idea a little.

(We will also need a custom compare routine, but the other solutions also need it).