Is it legal to sort index array (polygon_triangle) by pointee values like in the following code?
template< typename policy, typename random_access_iterator >
void build(const policy & p, random_access_iterator triangle_begin, random_access_iterator triangle_end)
{
using iterator_traits = thrust::iterator_traits< random_access_iterator >;
static_assert(std::is_base_of< std::random_access_iterator_tag, typename iterator_traits::iterator_category >::value, "!");
using triangle_type = typename iterator_traits::value_type;
auto triangle_count = std::size_t(thrust::distance(triangle_begin, triangle_end));
thrust::cuda::vector< int > polygon_triangle{triangle_count};
thrust::sequence(p, polygon_triangle.begin(), polygon_triangle.end());
using centroid_type = thrust::tuple< float, float, float >;
auto to_centroid = [] __host__ __device__ (triangle_type t) -> centroid_type
{
auto centroid = t.A + t.B + t.C;
return {centroid.x, centroid.y, centroid.z};
};
auto polygon_begin = thrust::make_permutation_iterator(triangle_begin, polygon_triangle.cbegin());
auto centroid_begin = thrust::make_transform_iterator(polygon_begin, to_centroid);
thrust::sort_by_key(p, centroid_begin, thrust::next(centroid_begin, triangle_count), polygon_triangle.begin());
// ...
}