digitalmars.D.learn - Declaring constant references in struct members
- David Zhang (10/10) Feb 15 2017 Hi,
- Adam D. Ruppe (4/7) Feb 15 2017 import std.typecons;
- David Zhang (15/23) Feb 15 2017 Is there a similar mechanism for one struct holding another?
- Adam D. Ruppe (3/4) Feb 15 2017 You'd have to make the member a pointer to the struct.
- H. S. Teoh via Digitalmars-d-learn (5/18) Feb 15 2017 Maybe have a look at std.typecons.Rebindable?
Hi, Say I have a struct S that holds a reference to an object O. Is there a way to express that I want to be able to change the reference, but not what the reference points to? Thanks. struct S { O object; } class O { size_t things. }
Feb 15 2017
On Thursday, 16 February 2017 at 00:43:30 UTC, David Zhang wrote:struct S { O object; }import std.typecons; Rebindable!O object; http://dpldocs.info/experimental-docs/std.typecons.Rebindable.html
Feb 15 2017
On Thursday, 16 February 2017 at 00:49:45 UTC, Adam D. Ruppe wrote:On Thursday, 16 February 2017 at 00:43:30 UTC, David Zhang wrote:Is there a similar mechanism for one struct holding another? Otherwise, you get a cannot modify X with immutable members error. eg: struct A { B b; } struct B { const size_t something; } A a = A(B(16)); //attempt to replace a.b with new B a.b = B(32); //error: cannot modify struct a.b B with immutable membersstruct S { O object; }import std.typecons; Rebindable!O object; http://dpldocs.info/experimental-docs/std.typecons.Rebindable.html
Feb 15 2017
On Thursday, 16 February 2017 at 01:05:58 UTC, David Zhang wrote:Is there a similar mechanism for one struct holding another?You'd have to make the member a pointer to the struct. immutable(B)* b;
Feb 15 2017
On Thu, Feb 16, 2017 at 12:43:30AM +0000, David Zhang via Digitalmars-d-learn wrote:Hi, Say I have a struct S that holds a reference to an object O. Is there a way to express that I want to be able to change the reference, but not what the reference points to? Thanks. struct S { O object; } class O { size_t things. }Maybe have a look at std.typecons.Rebindable? T -- What do you call optometrist jokes? Vitreous humor.
Feb 15 2017