Containers

deadalnix deadalnix at gmail.com
Wed Sep 1 20:26:37 UTC 2021


On Wednesday, 1 September 2021 at 18:32:29 UTC, Paul Backus wrote:
> On Wednesday, 1 September 2021 at 18:23:06 UTC, deadalnix wrote:
>> No you right, this is not what I meant (but this is def what I 
>> wrote).
>>
>> I meant that int[][] or int[]* turtle the qualifier down.
>
> Are you sure?
>
> ```d
> void manipulate(const(int)[][] arr) {}
>
> void main()
> {
>     const(int[][]) arr;
>     manipulate(arr);
>     // Error: cannot pass argument `arr` of type 
> `const(int[][])`
>     // to parameter `const(int)[][] arr`
> }
> ```

Yes, const(int[][]) is effectively const(const(const(int)[])[]).

In the same way, you want const(Vector!int[]) to be 
const(const(Vector!(const(int))[]).

Which means that you should be able to convert implicitly a 
reference to a Vector!int into a reference to a 
Vector!(const(int)).

In your example, you remove const qualifiers, so it obviously 
doesn't work. But it work in the other direction, when you add 
them. It won't for a collection even with an implicit cast 
operation, as what is really desired is some kind of 
reinterpret_cast.


More information about the Digitalmars-d mailing list