hasOnUnchecked

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.

@safe
template hasOnUnchecked (
Hook
) {
enum hasOnUnchecked;
enum hasOnUnchecked;
}

Examples

1 struct Foo {}
2 struct Bar { static void onUnchecked() { } }
3 struct Hook {
4     static immutable bool enableCopyConstructor = false;
5     static void onUnchecked() @safe { throw new Exception("result unchecked"); }
6 }
7 
8 // template checks
9 static assert(!hasOnUnchecked!Foo);
10 static assert(!__traits(compiles, hasOnUnchecked!Bar)); // missing disabled constructor
11 static assert(hasOnUnchecked!Hook);
12 
13 // copy constructor
14 auto exp = ok!(string, Hook)(42);
15 auto exp2 = err!(int, Hook)("foo");
16 static assert(!__traits(compiles, exp.andThen(ok!(string, Hook)(42)))); // disabled cc
17 assert(exp.andThen(exp2).error == "foo"); // passed by ref so no this(this) called
18 
19 // check for checked result
20 assertThrown({ ok!(string, Hook)(42); }());
21 assertThrown({ err!(void, Hook)("foo"); }());

Meta