What is the state of @property?

Salih Dincer salihdb at hotmail.com
Sun Aug 28 13:43:06 UTC 2022


On Thursday, 25 August 2022 at 03:49:07 UTC, Steven Schveighoffer 
wrote:
> It does just about nothing. The only discernable difference is 
> `typeof`:
>
> ```d
> struct S
> {
>     int prop1() { return 1; }
>     @property int prop2() { return 2; }
> }
>
> pragma(msg, typeof(S.prop1)); // int()
> pragma(msg, typeof(S.prop2)); // int
> ```

The function has parameters, the difference you're pointing isn't 
even visible :)
```d
struct S
{
     int prop1(int a) { return a; }
     @property int prop2(int b) { return b; }
}

pragma(msg, typeof(S.prop1(1))); // int
pragma(msg, typeof(S.prop2(2))); // int
```

**PS.** I could not work my last code in [the 
playground](https://run.dlang.io). The reason is `writeln`'s 
choices. I guess new version doesn't get along well with 
`@property`...

SDB at 79


More information about the Digitalmars-d mailing list