Copy constructor is enabled so the reference counting makes sense
Enabled reference counted payload
// behavior checks static assert(!isDefaultConstructorEnabled!RCAbort); static assert(isCopyConstructorEnabled!RCAbort); static assert(isRefCountedPayloadEnabled!RCAbort); // basics assert(ok!(string, RCAbort)(42) == 42); assert(err!(int, RCAbort)("foo").error == "foo"); // checked { auto res = ok!(string, RCAbort)(42); assert(!res.checked); assert(res); assert(res.checked); } // unchecked - throws assert version (D_Exceptions) () @trusted { assertThrown!Throwable({ ok!(string, RCAbort)(42); }()); }(); { auto res = ok!(string, RCAbort)(42); { auto res2 = res; assert(!res.checked); assert(res.refCount == 2); assert(res2.refCount == 2); } assert(res.refCount == 1); assert(res.hasValue); } // chaining assert(err!(int, RCAbort)("foo").orElse!(() => ok!(string, RCAbort)(42)) == 42); assert(ok!(string, RCAbort)(42).andThen!(() => err!(int, RCAbort)("foo")).error == "foo"); version (D_Exceptions) { () @trusted { assertThrown!Throwable(err!(int, RCAbort)("foo").orElse!(() => ok!(string, RCAbort)(42))); assertThrown!Throwable(ok!(string, RCAbort)(42).andThen!(() => err!(int, RCAbort)("foo"))); }(); }
Hook implementation that behaves same as Abort hook, but uses refcounted payload instead, which also enables us to check, if the result was properly checked before it is discarded.