#What's the correct way of sorting with NativeSort?

1 messages · Page 1 of 1 (latest)

cunning laurel
#

I wanted to make a generic arg-sort using NativeSort like this:

(...)
  sortedIndexes.Sort(
    new ArgSort<float>
    {
      Values = endTimes,
    }
  );
}

// Also tried T : unmanaged
private struct ArgSort<T> : IComparer<int> where T : struct, IComparable
{
  public NativeArray<T> Values;

  public int Compare(int x, int y)
  {
    return Values[x].CompareTo(Values[y]);
  }
}

But I get the following error:
Error: Burst error BC1020: Boxing a valuetype `System.Single` to a managed object is not supported

Is the problem using a generic parameter, even though it's limited to structs/unmanaged types?

trim terrace
#

You’re using the wrong interface for the constraint on T, it should be IComparable<T>, not the non-generic one