mutable reference to const object

Denis Koroskin 2korden at gmail.com
Tue Oct 12 02:13:45 PDT 2010


On Tue, 12 Oct 2010 13:07:59 +0400, Benjamin Thaut  
<code at benjamin-thaut.de> wrote:

> I want to have a mutable reference to a const object. So that I can  
> reasign the reference but can not modifiy the object. Is this possible  
> in D 2.0? I found tailconst in the const FAQ but as it is not  
> implemented in D 2.0 I'm clueless how to realize this.
>

For pointers:

const(int)* c = new int();
c = new int(); // reassign

For references:

import std.typecons;

Rebindable!(Object) o = new Object();
o = new Object();


More information about the Digitalmars-d-learn mailing list