Does remove immutability using cast to pass in a function make sense?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Sep 22 20:34:21 PDT 2014


On 09/22/2014 07:07 PM, AsmMan wrote:
> I have this array:
>
> static immutable string[] months = ["jan", "fev", ...];
>
> I need to pass it into canFind(). But it doesn't works with immutables
> so I need to cast it like in canFind(cast(string[]) months, month) to
> work. There's a reason related to design why it doesn't work with
> immutables or a function just wasn't written?
>
> What I want to know is if I'm doing something wrong in casting it to
> work. I know from C which such casts should be done carefully

What is the compiler version? The following works with dmd git head:

import std.algorithm;

static immutable string[] months = ["jan", "fev" ];

void main()
{
     assert(months.canFind("jan"));
}

If it still doesn't work for you please show us a minimal program that 
demonstrates the problem.

Ali



More information about the Digitalmars-d-learn mailing list