RfC for language feature: rvalue struct
FeepingCreature
feepingcreature at gmail.com
Wed Feb 1 07:48:38 UTC 2023
On Tuesday, 31 January 2023 at 18:30:44 UTC, Ola Fosheim Grøstad
wrote:
> On Tuesday, 31 January 2023 at 18:13:58 UTC, Ola Fosheim
> Grøstad wrote:
>> E.g. C# introduced "record" in addition to "struct" and
>> "class" to get slightly different value semantics, but as far
>> as I can tell it is only a rewrite.
>
> Or maybe it isn't (shrug). Anyway, you might want to look at
> the C# "with" statement:
>
> https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/records#non-destructive-mutation
Yes, that's exactly what we want!
What we use right now for `with` is
```
immutable struct S { int value; mixin(GenerateThis); }
S s = S(5);
S butFour = s.rebuild!(a => a.value = 4);
```
Which seems to work fine.
More information about the Digitalmars-d
mailing list