[Issue 5984] add new keywords obj_const and obj_immutable to make it possible to declare mutable reference variables referencing const or immutable class instances

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 11 13:23:54 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5984


kennytm at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm at gmail.com


--- Comment #1 from kennytm at gmail.com 2011-05-11 13:19:54 PDT ---
How is this better than the 'const(Object) ref' syntax*?

    class A { ... }

    immutable(A) func(immutable A a1, immutable A a2) {
        immutable(A) ref a_ptr = null;
        ...
    }

and

    const(ClassName)ref[] myArray;

Actually there is already std.typecons.Rebindable which mostly works (uglily):

    class A { ... }

    immutable(A) func(immutable A a1, immutable A a2) {
        Rebindable!(immutable(A)) a_ptr = null;
        ...
    }

and

    Rebindable!(const(ClassName))[] myArray;
    myArray.length = 1;
    myArray[0] = constant_object;
    myArray ~= rebindable(constant_object);

*: https://github.com/D-Programming-Language/dmd/pull/3

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list