IIndexable<T> #108592
-
I'm doing some work on creating generic heatmaps and one thing I need to do is transform a Vector (float) to a Point (integer). In making my solution generic, I was really surprised that the only thing I needed for my Points to implement this: /// <summary>Indexer provider for value types of immutable length.</summary>
public interface IIndexable<T> : IEnumerable<T>
{
static abstract int Count { get; }
T this[int index] { get; set; }
}
public struct Point2 : IIndexable<int>
{
public int X;
public int Y;
public static int Count => 2;
public IEnumerator<int> GetEnumerator()
{
yield return X;
yield return Y;
}
}
public struct Point3 : IIndexable<int>
{
// ...
} @tannergooding I think this could benefit generic vectors (floating or integer) a lot, since it abstracts the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The API itself is very similar to |
Beta Was this translation helpful? Give feedback.
It sounds related to the const generics proposal and fixed size arrays. There's no convenience at present.