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
 
 
Sent: Wednesday, March 11, 2026 at 5:07 AM
From: "Rainer Deyke via Boost" <boost@lists.boost.org>
To: boost@lists.boost.org
Cc: "Rainer Deyke" <rdeyke@gmail.com>
Subject: [boost] Re: Interest check: Boost.Algorithm.Statsort — O(n log log n) sorting
On 3/9/26 23:08, Peter Taraba via Boost wrote:
> Supports any std::is_arithmetic<T> type (int, float, double, etc.)

I don't think I've ever sorted a container of plain numbers in a real
program. However, I have sorted by complex objects by their numeric
attributes fairly often, i.e.:

struct my_complex_type {
std::string name;
int z;
};

std::vector<my_complex_type> my_vector;
std::sort(
my_vector.begin(),
my_vector.end(),
[](auto const &a, auto const &b) { return a.z < b.z; });

Can statsort work with this kind of object?


--
Rainer Deyke - rainerd@eldwood.com

_______________________________________________
Boost mailing list -- boost@lists.boost.org
To unsubscribe send an email to boost-leave@lists.boost.org
https://lists.boost.org/mailman3/lists/boost.lists.boost.org/
Archived at: https://lists.boost.org/archives/list/boost@lists.boost.org/message/GK2WPCZU5M7Z2LJIR4F4J2D3XLNMY4LE/