Sort an array of indices. Sort an array of pointers.Quote:
For example you may have a thread object, each has a unique thread ID, priority and all other related information. Each thread object is certainly unique so you never ever want to duplicate it at any moment. Now, the operating system need to sort these thread objects by priority. How do you do it? It must be sorted without making duplications at any given moment.
Ridiculous. You ARE copying the object. Bit by bit. One object's data ends up in a different memory location from where it was instantiated. That data is a copy of the original object. It is NOT the original object.Quote:
And under this situation Qsort would work better than std::sort, because it swaps objects without actually making any copies.
Wow, deja-vu!
If you need to make copies of the class, then the class should not be designed with copying prohibited, in which case, std::sort will work perfectly.Quote:
There will be cases you are not satisfied with an indirect index array, but you want to sort the objects themselves directly.
It is not a limitation. QSort is a poor tool because it does not respect my class design decisions.Quote:
std::sort can only sort objects that an appropriate copy operation can be carried out, and is not prohibited to carry out. Qsort does not have such limitation.
Regards,
Bassman
