Re: how to declare an immutable class?

2016-08-12 Thread Charles Hixson via Digitalmars-d-learn
Thank you both. On 08/12/2016 01:35 AM, Jonathan M Davis via Digitalmars-d-learn wrote: On Friday, August 12, 2016 05:25:45 Mike Parker via Digitalmars-d-learn wrote: immutable class Foo { ... } is the same as declaring every member of Foo as immutable, just as final class Foo { ... } makes

Re: how to declare an immutable class?

2016-08-12 Thread Mike Parker via Digitalmars-d-learn
On Friday, 12 August 2016 at 08:35:54 UTC, Jonathan M Davis wrote: On Friday, August 12, 2016 05:25:45 Mike Parker via Digitalmars-d-learn wrote: immutable class Foo { ... } is the same as declaring every member of Foo as immutable, just as final class Foo { ... } makes every method final.

Re: how to declare an immutable class?

2016-08-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, August 11, 2016 21:49:46 Charles Hixson via Digitalmars-d-learn wrote: > It works, it's just not the syntax that I'd prefer. And it leaves me > wondering exactly what > immutable class Msg {...} > was declaring. All it does is make the members of the class immutable. It doesn't

Re: how to declare an immutable class?

2016-08-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, August 12, 2016 05:25:45 Mike Parker via Digitalmars-d-learn wrote: > immutable class Foo { ... } is the same as declaring every member > of Foo as immutable, just as final class Foo { ... } makes every > method final. I'm not sure that that's quite the same thing, because there is

Re: how to declare an immutable class?

2016-08-11 Thread Mike Parker via Digitalmars-d-learn
On Friday, 12 August 2016 at 04:49:46 UTC, Charles Hixson wrote: It works, it's just not the syntax that I'd prefer. And it leaves me wondering exactly what immutable class Msg {...} was declaring. This should demonstrate: ``` immutable class iMsg { int getX() { return 10; } } class

Re: how to declare an immutable class?

2016-08-11 Thread Charles Hixson via Digitalmars-d-learn
On 08/11/2016 06:33 PM, Mike Parker via Digitalmars-d-learn wrote: On Friday, 12 August 2016 at 00:44:31 UTC, Charles Hixson wrote: A way around this, which may be the same as the approach used by string was: alias immutable(Msg_)Msg; classMsg_ { ... This is exactly what Jonathan

Re: how to declare an immutable class?

2016-08-11 Thread Mike Parker via Digitalmars-d-learn
On Friday, 12 August 2016 at 00:44:31 UTC, Charles Hixson wrote: A way around this, which may be the same as the approach used by string was: alias immutable(Msg_)Msg; classMsg_ { ... This is exactly what Jonathan suggested in the post above. And yes, it's how string is handled:

Re: how to declare an immutable class?

2016-08-11 Thread Charles Hixson via Digitalmars-d-learn
A way around this, which may be the same as the approach used by string was: alias immutable(Msg_)Msg; classMsg_ { ... This so far appears to do what I want. The only problem is that it introduces an extraneous symbol, which I would prefer to avoid. OTOH, I did fix a few problems

Re: how to declare an immutable class?

2016-08-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, August 11, 2016 10:56:59 Charles Hixson via Digitalmars-d-learn wrote: > I want to declare a class all instances of which will be immutable, and > all references to which will be inherently immutable (so that I don't > need to slip a huge number of "immutable" statements in my code).

Re: how to declare an immutable class?

2016-08-11 Thread sldkf via Digitalmars-d-learn
On Thursday, 11 August 2016 at 17:56:59 UTC, Charles Hixson wrote: Does anyone know the correct approach? I do: °° immutable class Foo { this() {} } void main() { auto foo = new immutable(Foo); } °° But take care because you

how to declare an immutable class?

2016-08-11 Thread Charles Hixson via Digitalmars-d-learn
I want to declare a class all instances of which will be immutable, and all references to which will be inherently immutable (so that I don't need to slip a huge number of "immutable" statements in my code). This is surely possible, because string acts just that way, but I can't figure out