On 04/17/2017 11:30 AM, Russel Winder via Digitalmars-d-learn wrote:
I find myself in need of constructing an empty Result object. I tried
takeNone!Result, but obviously the type Result doesn't appear to exist.
Anyone any ideas?


(Not a complete solution; just sharing your pain.)

I had the same problem here:


http://ddili.org/ders/d.en/fibers.html#ix_fibers.Generator,%20std.concurrency

The solution I could use there is less than ideal and may not apply in all cases. I used typeof and was able to satisfy it with an empty delegate:

/* Returns an InputRange to the nodes of the tree. The
 * returned range is empty if the tree has no elements (i.e.
 * if 'root' is 'null'). */
auto byNode(const(Tree) tree) {
    alias RangeType = typeof(byNode(tree.root));

    return (tree.root
            ? byNode(tree.root)
            : new RangeType(() {}));    // ← Empty range
}

Ali

Reply via email to