I've just askedWhat's the idiomatic way to get the sort order of data, without actually applying it?(or see the original it was found to be a dupe on). So, I want to implement properly what seems to be the only suggested option - generating an array of indices and sorting it by the original data's relative order. Here's my code (ignoring includes):template<typename RAIterator, typename Comparator, typename Size = size_t>inline std::vector<Size>sorted_indices(RAIterator first, RAIterator last, Comparator comparator){    std::vector<Size> result(last - first);    std::iota(result.begin(), result.end(), 0);    auto adapted_comparator = [&first, comparator](Size lhs, Size rhs) {        return comparator(first[lhs], first[rhs]);    };    std::sort(result.begin(), result.end(), adapted_comparator);    return result;}template<typename RAIterator, typename Size = size_t>inline std::vector<Size>sorted_indices(RAIterator first, RAIterator last){    using value_type = typename std::iterator_traits<RAIterator>::value_type;    auto comparator = [](const value_type& lhs, const value_type& rhs) { return lhs < rhs; };    return sorted_indices<RAIterator, decltype(comparator), Size>(first, last, comparator);}template<typename Container, typename Comparator, typename Size = typename Container::size_type>inline std::vector<Size> sorted_indices(Container& container, Comparator comparator){    return sorted_indices<typename Container::const_iterator, Size>(        std::begin(container), std::end(container), comparator);}template<typename Container, typename Size = typename Container::size_type>inline std::vector<Size> sorted_indices(Container& container){    return sorted_indices<typename Container::const_iterator, Size>(        std::begin(container), std::end(container));}Have I covered all my bases or is there something I might be missing? Also, how legitimate is it to return the vector of indices?
Get the indices of a range elements by relative order of the values
c++;sorting;iterator