Exposing it would allow writing extension methods on it, so one could do something like Split('\0').ToArray().
// Not possible to write currently
public static T[] ToArray<T>(this MemoryExtensions.SpanSplitEnumerator<T> enumerator) where T : IEquatable<T>
934 #104534
API Proposal
public ref struct SpanSplitEnumerator<T>
{
public SpanSplitEnumerator<T> GetEnumerator();
public bool MoveNext();
public Range Current { get; }
+ public ReadOnlySpan<T> Span;
}
API Usage
// This is a common pattern in Win32
public static string[] SplitStringList(this ReadOnlySpan<char> strings)
=> strings.Split('\0').ToArray();
// Usable by above and any other code that needs to convert to an array
public static T[] ToArray<T>(this MemoryExtensions.SpanSplitEnumerator<T> enumerator) where T : IEquatable<T>
// ... implementation that grabs the ranges and creates the appropriately sized array if needed
Alternative Designs
Could possibly expose range related methods so one could do something like enumerator[enumerator.Current]?
Background and motivation
Exposing it would allow writing extension methods on it, so one could do something like
Split('\0').ToArray()
.934 #104534
API Proposal
API Usage
Alternative Designs
Could possibly expose range related methods so one could do something like
enumerator[enumerator.Current]
?Risks
None known.