I’d like to find the sort order of a vector, for example, without reordering the vector.
I can think of several ways to do this, I’m wondering if I’m missing some built-in STL or BOOST way to do this.
I imagine if the functionality were available the code would end up looking something like this:
std::vector<float> unsortedSeq;
unsortedSeq.push_back( 1.1 );
unsortedSeq.push_back( 1.0 );
unsortedSeq.push_back( 0.5 );
unsortedSeq.push_back( 1.2 );
unsortedSeq.push_back( 1.15 );
std::list<std::size_t> sortOrder;
std::sort_indices( unsortedSeq.begin(), unsortedSeq.end(), sortOrder.begin() );
BOOST_FOREACH( std::size_t index, sortOrder )
{
std::cout << index << "\n"
}
2
1
0
4
3
Anyone know any STL or BOOST-sims that would do what I’m asking about as simply as shown?
You would do something like this:
This generates a vector of indices, and then sorts them based on the vector of actual stuff.