An optional/maybe type with range semantics
aliak
something at something.com
Tue Feb 27 14:17:12 UTC 2018
On Tuesday, 27 February 2018 at 11:58:34 UTC, Dukc wrote:
> On Monday, 26 February 2018 at 20:04:14 UTC, aliak wrote:
>> Guess I could do a pointer and call new when i need to store a
>> value instead. Or maybe it's better to do it like above and
>> store as value type with default value and a boolean at the
>> site. Not sure.
>
> You do not need a separate boolean field. If someone assigns
> "none" or calls popFront() just assign the pointer to null.
> When someone queries empty, you check whether the pointer
> points to null. The default value is easy too:
> typeof(element).init.
Either you misunderstood or my writing was not clear. I meant
you'd need a boolean if you were using a value type (was just
speaking out loud as another alternative to a pointer or array)
>
> That's the superior design, because it does not need any excess
> memory for the empty flag.
It means using new, so not sure how superior it is compare to
storing a value type.
More information about the Digitalmars-d-announce
mailing list