Hi Rainer,
Great question — and a fair one. You're right that real-world code rarely sorts plain numeric vectors; sorting complex objects by a field is far more common.
I've added projection overloads to statsort that address exactly the pattern you described:
boost::algorithm::statsort(my_vector,
[](const my_complex_type& x) { return x.z; });
The projection must return an arithmetic type, which is then used as the sort key. Both the container and iterator interfaces support it:
// Container overload
boost::algorithm::statsort(my_vector,
[](const my_complex_type& x) { return x.z; });
// Iterator overload
boost::algorithm::statsort(my_vector.begin(), my_vector.end(),
[](const my_complex_type& x) { return x.z; });
The updated code is on GitHub: https://github.com/drpt78/statsort
Does this cover your use case? Happy to hear if there are other patterns I should consider.
Best,
Peter & Claude AI
https://orcid.org/0000-0002-8199-3723