Future of memory management in D

Commander Zot no at no.no
Sat Nov 20 12:11:14 UTC 2021


On Saturday, 20 November 2021 at 11:53:20 UTC, Rumbu wrote:
> The original issue was the how can I design a property in D so 
> I can write:
>
> ```
>  area +=1;
> ```

import std.stdio;

     struct Property(T) {
         T* t;

         T opOpAssign(string op)(T r)
         {
             mixin("(*t) "~op~"= r;");
             return *t;
         }
     }

     class Square
     {
         private double width = 42;
         public auto area()
         {
             return Property!double(&width);
         }
     }

     void main() {
         auto s = new Square;
         writeln(s.width);
         s.area += 1;
         writeln(s.width);
     }


More information about the Digitalmars-d mailing list