Declaring constant references in struct members
David Zhang via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Feb 15 17:05:58 PST 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:
>> struct S {
>> O object;
>> }
>
> import std.typecons;
>
> Rebindable!O object;
>
> http://dpldocs.info/experimental-docs/std.typecons.Rebindable.html
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
members
More information about the Digitalmars-d-learn
mailing list