Inside of D’s GC in Russian
Kagamin
spam at here.lot
Tue Apr 23 13:38:41 UTC 2024
One time I wanted `inout` in C#, that uses wrapper types for
slices. How would you design it without `inout`?
```
Span<T> Shrink<T>(Span<T> s, int length)
{
if (s.Length > length) return s.Slice(0, length);
return s;
}
ReadOnlySpan<T> Shrink<T>(ReadOnlySpan<T> s, int length)
{
if (s.Length > length) return s.Slice(0, length);
return s;
}
void test(byte[] a)
{
//var b = Shrink(a, 2); //can't infer type
var b2 = Shrink<byte>(a, 2);
}
More information about the Digitalmars-d
mailing list