Fixing const arrays

Max Samukha maxsamukha at gmail.com
Mon Dec 12 02:38:35 PST 2011


On 12/12/2011 12:33 AM, deadalnix wrote:
> I think you misunderstood the idea. The point was to remove constness of
> something passed by value, as long as it possible (native types, pointer
> (but not pointee), slices (but not what is in the slice), structs as
> long as they have no indirection in them).

Then, should the rule be generalized to include any type that has no 
indirections to mutable data?

struct S2
{
     immutable(int)* x;
}

struct S
{
     string s;
     S2 s2;
}

void foo(T)(T s) if (!is(T == immutable)) {  }
immutable S s;
foo(s);

The argument is passed by value, the qualifier can be safely removed, so 
the call is rewritten to

foo(cast(S)s);

Any potential problems with that?






More information about the Digitalmars-d mailing list