Empty Result
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Apr 17 12:05:19 PDT 2017
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
More information about the Digitalmars-d-learn
mailing list