non empty slices
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jun 2 15:00:16 PDT 2016
On 06/02/2016 10:11 PM, Alex wrote:
> The cool thing about the Algebraic is as I expected, that it doesn't
> change it's type... And the hard thing is, that I'm not used to its
> Empty, Many, ... things yet.
I just made those up on the spot. Note that Many is not actually
implemented at all. There is no check that the array has at least two
elements. And Empty is just there, because I needed a type for the
Algebraic.
> But the question remains how to keep this @nogc?
Apparently, it's Algebraic that isn't @nogc. I don't know what it
allocates. Maybe it allocates space for large types (but there aren't
any here), or maybe it can throw a GC-allocated exception.
> I wonder at the line
> with peek... and why it is not just returning the value...
I wouldn't expect that to be the problem with @nogc. As far as I see,
the pointer is used as a way to return "not found" in the form of null.
When you get a non-null pointer it's probably just into the Algebraic.
More information about the Digitalmars-d-learn
mailing list