Challenge: write a reference counted slice that works as much as possible like a built-in slice

deadalnix deadalnix at gmail.com
Fri Nov 12 15:39:57 UTC 2021


On Thursday, 11 November 2021 at 21:46:29 UTC, Andrei 
Alexandrescu wrote:
> I keep on thinking of proposing opFunCall() that is called 
> whenever an object is passed by value into a function. The 
> lowering for such objects would be:
>
> fun(obj);
>
> ===>
>
> fun(obj.opFunCall());

This has little to do with function calls. The same problem will 
exist for assignment for instance. Now you could also override 
opAssign, but you see where I'm going with that.

Not only does the head const needs to be dropped, but this needs 
to happen implicitly AND aggressively.

By implicitly, I meant hat the conversion doesn't require extra 
syntax, as in:
```d
const int[] a;
const(int)[] b = a; // OK
```

And by aggressively, I mean that it happens as soon as possible, 
not simply when a conversion is needed. For instance:
```d

void foo(T)(T t) {
     writeln(T.stringof);
}

void main() {
     const int[] a;
     foo(a); // Prints const(int)[]
}
```


More information about the Digitalmars-d mailing list