Adding syntacti sugar for simple "readonly" attribute ?

bauss jj_1337 at live.dk
Fri Oct 27 09:06:24 UTC 2017


On Friday, 27 October 2017 at 06:49:47 UTC, Jacob Carlborg wrote:
> On 2017-10-27 01:04, bauss wrote:
>
>> The first example would not equal the second, because you 
>> could set bar from anywhere within the module.
>> 
>> Immutable will already do your behavior.
>> 
>> class Foo
>> {
>>      immutable string bar;
>> 
>>      this(string baz)
>>      {
>>          bar = baz;
>>      }
>> }
>
> That only works for primitive types. For anything else (like a 
> class or struct) you won't be able to modify the internal 
> state. While with the with the initial example you can.

Ahh yeah, that's true. I wasn't thinking that far


More information about the Digitalmars-d mailing list