www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Mutable reference to const objects

reply "Yuxuan Shui" <yshuiv7 gmail.com> writes:
How do I express a mutable reference to a const object in D?

What I want to do is to define a variable, which refers a 
constant object, but I can change which constant object it is 
referring. Is this possible?
Jul 01 2015
parent reply "Yuxuan Shui" <yshuiv7 gmail.com> writes:
On Wednesday, 1 July 2015 at 08:30:23 UTC, Yuxuan Shui wrote:
 How do I express a mutable reference to a const object in D?

 What I want to do is to define a variable, which refers a 
 constant object, but I can change which constant object it is 
 referring. Is this possible?
I wonder will something like: class Const(T): const(T) inner; alias this inner; } work?
Jul 01 2015
parent "Nicholas Wilson" <iamthewilsonator hotmail.com> writes:
On Wednesday, 1 July 2015 at 08:33:44 UTC, Yuxuan Shui wrote:
 On Wednesday, 1 July 2015 at 08:30:23 UTC, Yuxuan Shui wrote:
 How do I express a mutable reference to a const object in D?

 What I want to do is to define a variable, which refers a 
 constant object, but I can change which constant object it is 
 referring. Is this possible?
I wonder will something like: class Const(T): const(T) inner; alias this inner; } work?
You want rebindable. see http://dlang.org/phobos/std_typecons.html
Jul 01 2015