Personally, I’d also be happy with a subroutine:
call order_inplace(table,indx)
I can imagine delegating both the partitioning and reordering to a derived type which accepts a predicate function, or a mask expression. I’m just not sure how to make it sufficiently generic?
Could a generic reorder be achieved with a class(*) input argument? After all, at this point we don’t care about the contents of the table items but just that they are moved to the right place.
Edit: with respect to partioning
The partitioned subroutine, could use the true_pos function of @beliavsky given here.