I currently have an array of pair<double, int>
which I sort using a simple custom comparator function e.g.
// compare by first
int sort_index_lcomparator(const pair<double, int>& a, const pair<double, int>& b) {
return a.first < b.first;
}
// then sort simply like
pair<double, int> arr[size];
std::sort(arr, arr + size, sort_index_lcomparator);
I'm actually interested in the index order and not in the sorted doubles. My problem is that I would like to change away from this structure and have instead a struct of two arrays rather than an array of a struct i.e. I would like to optimize for locality and auto-vectorization but in this case I need an overloaded swap
which is attached to a type specifically. I guess I would need something along the lines of redefining swap
for the double
type and keep both arrays in sync in such custom swap
. Is there a way to "override" swap
in such a manner within a limited scope?