Cached property (translate Python -> D)

Victor Porton porton at narod.ru
Tue Jan 29 18:02:04 UTC 2019


On Tuesday, 29 January 2019 at 18:00:36 UTC, H. S. Teoh wrote:
> You could have just used std.typecons.Nullable instead of 
> reimplementing it yourself:
>
> 	private Nullable!T _myField;
> 	@property T myField() {
> 		if (_myField.isNull)
> 			_myField = ...; // initialize it here
> 		return _myField;
> 	}

I know, but how it is better than my code?


More information about the Digitalmars-d mailing list