- I have a vector of custom Struct that needs to be sorted on different criteria each time
- Implementing operator < will allow only one criteria
- But I want to be able to specify sorting criteria each time I call C++ standard sort.
How to do that?
- Please note it is better to be efficient in running time..
Thanks
You can define what comparison function to use in each run of the sort algorithm by using the third argument:
A simple example: