Nullable or Optional? Or something else?

Rainer Deyke rainerd at eldwood.com
Thu Sep 10 09:47:35 PDT 2009


Steven Schveighoffer wrote:
> struct AlgebraicFunction {
>    double getMaximum() {
>      if (!cache_valid) {
>        this.cachedMaximum = this.veryExpensiveCalculation();
>        cache_valid = true;
>      }
>      return this.cachedMaximum; // hey, I thought you only use struct
> pointers like (*x).member?

I kind of forgot that 'this' is a pointer inside structs.

>    }
> 
>    private Optional!double cached_maximum;
>    private bool cache_valid = false;
> }

If cached_maximum and cache_valid are the only members of
AlgebraicFunction, you might be able to get away with that.  If you have
several different cached values, not so much.


-- 
Rainer Deyke - rainerd at eldwood.com



More information about the Digitalmars-d mailing list