-
Couldn't load subscription status.
- Fork 5.2k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtimein-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Background and motivation
We've shipped multiple ref struct enumerators. Previously they couldn't implement IEnumerator<T>, but now they can. We should have them do so.
API Proposal
namespace System
{
public static class MemoryExtensions
{
public ref struct SpanSplitEnumerator<T>
+ : IEnumerator<Range>
}
public readonly ref struct ReadOnlySpan<T>
{
public ref struct Enumerator
+ : IEnumerator<T>
}
public readonly ref struct Span<T>
{
public ref struct Enumerator
+ : IEnumerator<T>
}
}
namespace System.Text
{
public ref partial struct SpanLineEnumerator
+ : IEnumerator<ReadOnlySpan<char>>
public ref partial struct SpanRuneEnumerator
+ : IEnumerator<Rune>
}
namespace System.Numerics.Tensors
{
public readonly ref struct ReadOnlyTensorSpan<T>
{
public ref struct Enumerator :
+ : IEnumerator<T>
}
public readonly ref struct TensorSpan<T>
{
public ref struct Enumerator :
+ : IEnumerator<T>
}
}
namespace System.Text.RegularExpressions
{
public ref struct ValueMatchEnumerator
+ : IEnumerator<ValueMatch>
public ref struct ValueSplitEnumerator
+ : IEnumerator<Range>
}Notes:
- All remaining members of the interface not already exposed publicly will be implemented explicitly.
- Where the T is a ref struct, the IEnumerator.Current will throw NotSupportedException.
- Where possible with minimal interruption, IEnumerator.Reset will work, otherwise it'll throw NotSupportedException.
- IDisposable.Dispose nops on all of them.
API Usage
static int Sum<TEnumerator>(TEnumerator enumerator) where TEnumerator : IEnumerator<int>
{
int sum = 0;
while (enumerator.MoveNext()) sum += enumerator.Current;
return sum;
}Alternative Designs
No response
Risks
No response
hez2010, nil4, timcassell, julealgon, PaulusParssinen and 8 more
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Runtimein-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged