Nullable or Optional? Or something else?
Steven Schveighoffer
schveiguy at yahoo.com
Thu Sep 10 10:47:50 PDT 2009
On Thu, 10 Sep 2009 12:47:35 -0400, Rainer Deyke <rainerd at eldwood.com>
wrote:
>> }
>>
>> 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.
Why not?
private Optional!double cached_x;
private bool cachex_valid;
private Optional!double cached_y;
private bool cachey_valid;
I guess my point really should be that storing a boolean next to a value
isn't any different than storing them inside a struct with two distinct
ways of getting at them, especially as a privately cached value where the
interface isn't affected.
What makes Andrei's proposal compelling is that you can drop it into any
place where a value type or reference type is normally used (including
non-template functions) and it just works. Your method doesn't do that,
you need the dereference operator to get at the value type, so the code
needs to be specifically built to handle your "wrapper" type.
-Steve
More information about the Digitalmars-d
mailing list