Flagging special conditions on return from a function call

Paul Backus snarwin at gmail.com
Tue Jun 23 21:34:25 UTC 2020


On Tuesday, 23 June 2020 at 16:14:20 UTC, Denis wrote:
>> by presenting an interface that only compiles when both cases 
>> are covered, like fun().match((T t) => t, () => Error()).
>
> A complete solution wrapped in a tidy package -- I like it.
>
> Thanks for sharing.

If you're open to using Dub packages, I'd recommend sumtype [1] 
as an alternative to the standard-library Algebraic. It has much 
better compatibility with things like function attributes (@safe, 
nothrow, etc), mutability qualifiers, CTFE, and betterC, and also 
produces substantially more efficient code [2].

[1] https://code.dlang.org/packages/sumtype
[2] 
https://pbackus.github.io/blog/beating-stdvisit-without-really-trying.html


More information about the Digitalmars-d-learn mailing list