What is the state of @property?

Salih Dincer salihdb at hotmail.com
Thu Aug 25 14:49:51 UTC 2022


On Thursday, 25 August 2022 at 13:23:25 UTC, bauss wrote:
> Currently @property doesn't really do anything in this regard, 
> so I imagine that the code would work the same without 
> @property, no?

One benefit of @property is that it allows the compiler to infer 
automatically.  So it behaves like auto but superior! For example:

```d
import std.stdio;

struct ReverseS(int size)
{
   private char[size] bytes;
   private int index = size - 1;

   @property empty() {
     return index < 0;
   }

   @property front() {
     return bytes[index];
   }

   @property popFront() {
     --index;
   }
}

void main()
{
   char[9] text = "ytreporp@".dup;

   foreach(c; ReverseS!9(text)) {
     c.write;
   }
   writeln; // @property
}
```

SDB at 79



More information about the Digitalmars-d mailing list