Re: How to create an overwriteable struct that is always const?

2019-06-02 Thread David Zhang via Digitalmars-d-learn
Ah, fair enough.

Re: How to create an overwriteable struct that is always const?

2019-06-02 Thread ag0aep6g via Digitalmars-d-learn
On 02.06.19 04:22, David Zhang wrote: On Saturday, 1 June 2019 at 13:00:50 UTC, ag0aep6g wrote: How is setting/replacing different from modifying? e.g.:     S s;     this() { s = ...; }     update(S s) { this.s = s; }     mod(int i) { s.i = i; } // illegal Kinda like how strings can

Re: How to create an overwriteable struct that is always const?

2019-06-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, June 1, 2019 8:23:58 PM MDT David Zhang via Digitalmars-d-learn wrote: > On Saturday, 1 June 2019 at 16:30:12 UTC, Jonathan M Davis wrote: > > If any member variable of a struct is const, then you can't > > modify that member ever, and assignment isn't possible unless > > you

Re: How to create an overwriteable struct that is always const?

2019-06-01 Thread David Zhang via Digitalmars-d-learn
On Saturday, 1 June 2019 at 13:00:50 UTC, ag0aep6g wrote: How is setting/replacing different from modifying? e.g.: S s; this() { s = ...; } update(S s) { this.s = s; } mod(int i) { s.i = i; } // illegal Kinda like how strings can be copied and assigned to, but not

Re: How to create an overwriteable struct that is always const?

2019-06-01 Thread David Zhang via Digitalmars-d-learn
On Saturday, 1 June 2019 at 16:30:12 UTC, Jonathan M Davis wrote: If any member variable of a struct is const, then you can't modify that member ever, and assignment isn't possible unless you override opAssign so that it overwrites only the mutable members. It's very rare that it makes sense

Re: How to create an overwriteable struct that is always const?

2019-06-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, June 1, 2019 6:51:08 AM MDT David Zhang via Digitalmars-d-learn wrote: > Say I have a struct `S`: > > struct S { > /*const*/ char* pointer; > ... other members ... > > this(/*const*/ char* p, ... others ...) { > pointer = p; >

Re: How to create an overwriteable struct that is always const?

2019-06-01 Thread ag0aep6g via Digitalmars-d-learn
On 01.06.19 14:51, David Zhang wrote:     struct S {     /*const*/ char* pointer;     ... other members ...     this(/*const*/ char* p, ... others ...) {     pointer = p;     ...     }     } What I want, is to be able to use `S` in other data structures

Re: How to create an overwriteable struct that is always const?

2019-06-01 Thread drug via Digitalmars-d-learn
01.06.2019 15:55, drug пишет: Is there a type-safe way to do this? If this were a class, I'd try std.typecons.Rebindable. Ah, sorry))

Re: How to create an overwriteable struct that is always const?

2019-06-01 Thread drug via Digitalmars-d-learn
01.06.2019 15:51, David Zhang пишет: Say I have a struct `S`:     struct S {     /*const*/ char* pointer;     ... other members ...     this(/*const*/ char* p, ... others ...) {     pointer = p;     ...     }     } What I want, is to be able to use `S`

How to create an overwriteable struct that is always const?

2019-06-01 Thread David Zhang via Digitalmars-d-learn
Say I have a struct `S`: struct S { /*const*/ char* pointer; ... other members ... this(/*const*/ char* p, ... others ...) { pointer = p; ... } } What I want, is to be able to use `S` in other data structures with the following