struct Foo {} struct Bar { static void onUnchecked() { } } struct Hook { static immutable bool enableCopyConstructor = false; static void onUnchecked() @safe { throw new Exception("result unchecked"); } } // template checks static assert(!hasOnUnchecked!Foo); static assert(!__traits(compiles, hasOnUnchecked!Bar)); // missing disabled constructor static assert(hasOnUnchecked!Hook); // copy constructor auto exp = ok!(string, Hook)(42); auto exp2 = err!(int, Hook)("foo"); static assert(!__traits(compiles, exp.andThen(ok!(string, Hook)(42)))); // disabled cc assert(exp.andThen(exp2).error == "foo"); // passed by ref so no this(this) called // check for checked result assertThrown({ ok!(string, Hook)(42); }()); assertThrown({ err!(void, Hook)("foo"); }());
Template to determine if hook provides custom handler for case when the Expected result is not checked.
For this to work it currently also has to pass isCopyConstructorEnabled as this is implemented by simple flag controled on Expected destructor.