Inside of D’s GC in Russian
Dmitry Olshansky
dmitry.olsh at gmail.com
Wed Apr 24 13:06:49 UTC 2024
On Tuesday, 23 April 2024 at 13:38:41 UTC, Kagamin wrote:
> One time I wanted `inout` in C#, that uses wrapper types for
> slices. How would you design it without `inout`?
Have Span be a subtype of ReadOnlySpan, either through interfaces
and dynamic dispatch or through alias this and implicit
conversion.
>
> ```
> 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