new properties for basic types

Puming via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 14 03:45:06 PDT 2014


On Monday, 14 July 2014 at 10:28:30 UTC, Dominikus Dittes Scherkl 
wrote:
> Is it possible to write custom properties for basic types, so 
> that I can write e.g. "int.myProp" instead of "myProp!int()" 
> [analogue to x.myProp instead of myProp(x)]?

yes, just define a funciton with the first parameter int:

```d

@property int triple(int x)
{
   return x * 3;
}

void main()
{
   int x = 4;
   assert(12 == x.triple);
}
```


More information about the Digitalmars-d-learn mailing list