[Issue 5325] Mutable references to const/immutable/shared classes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jul 24 08:07:05 PDT 2013


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


monarchdodra at gmail.com changed:

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


--- Comment #4 from monarchdodra at gmail.com 2013-07-24 08:07:04 PDT ---
(In reply to comment #3)
> (In reply to comment #2)
> > How about making a distinction between const(Object) and const Object?
> > I think it would be less intrusive and more in line with the const(void)* vs.
> > const void* behavior.
> 
> That'll only work in the context where you're declaring a tail-const variable
> of type Object. If you're declaring an array of tail-const objects, or passing
> a tail-const object as a template parameter, you can't omit the parenthesis.
> But the ref postfix works:
> 
>    const(Object)ref[] arrayOfTailConstObjects;

Note that you can use std.typecons.Rebindable to achieve what you are doing:
Rebindable!C //Creates a simple an alias to C
Rebindable!(immutable C) Creates a mutable object that holds an immutable C.
Rebindable!(const C) Creates a mutable object that can hold any reference to C.

The thing is very light weight, so in theory, you can use it, and you should
have 0 overhead (in release)... Well, except if you use it inside algorithms
like emplace/array or whatnot, as they'll notice an elaborate opAssign, and
take a slower road.

It is, of course, pure and nothrow, but apparently, it is not @safe/@trusted,
but I don't see why... It should. I'll make a mental note to do it.

Unfortunately, it requires an import, and looks like ass. But it's your current
workaround. wish we had something simpler and more idomatic, but that's they
way it is. How does C# deal with this?

-- 
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