Is this a violation of const?

ag0aep6g anonymous at example.com
Sat Jul 30 10:34:09 UTC 2022


On 30.07.22 09:15, Salih Dincer wrote:
> It's possible to do this because it's immutable.  You don't need an 
> extra update() function anyway.
> 
> ```d
> void main()
> {
>      auto s = S("test A");
>      s.update = (_) { s.s = _; };
> 
>      s.update("test B");
>      assert(s.s == "test B");
> 
>      s.s = "test C";
>      assert(s.s == "test C");
> } // No compile error...
> ```

You're not making sense. Your `s` is mutable, not immutable.


More information about the Digitalmars-d-learn mailing list