Containers

Paul Backus snarwin at gmail.com
Wed Sep 1 13:22:46 UTC 2021


On Wednesday, 1 September 2021 at 12:52:47 UTC, deadalnix wrote:
> On Wednesday, 1 September 2021 at 11:57:01 UTC, Paul Backus 
> wrote:
>> With the implicit `opCast`/constructor approach (or the 
>> `opHeadMutable` approach), the compiler doesn't have to 
>> understand the relationships. It just needs to know the 
>> original type and the desired type, and call the appropriate 
>> user-defined function to perform the conversion.
>
> It still wouldn't work when manipulating things by reference.
>
> In fact, the litmus test for a solution to that problem should 
> be: can we reproduce the behavior of builtin types such as T* 
> or T[] with it?

It doesn't work when manipulating built-in types by reference 
either:

```d
void manipulate(ref const(int)[] arr) {}

void main()
{
     const(int[]) arr;
     manipulate(arr);
     // Error: cannot pass argument `arr` of type `const(int[])`
     // to parameter `ref const(int)[] arr`
}
```


More information about the Digitalmars-d mailing list