err

Creates an Expected object from an error value, with type inference.

@safe
Expected!(T, E, Hook)
err
(
T = void
Hook = Abort
E
)
(
auto ref E err
)

Examples

1 // implicit void value type
2 {
3     auto res = err("foo");
4     static assert(is(typeof(res) == Expected!(void, string)));
5     assert(!res);
6     assert(res.error == "foo");
7 }
8 
9 // bool
10 {
11     auto res = err!int("42");
12     static assert(is(typeof(res) == Expected!(int, string)));
13     assert(!res);
14     assert(res.error == "42");
15 }
16 
17 // other error type
18 {
19     auto res = err!bool(42);
20     static assert(is(typeof(res) == Expected!(bool, int)));
21     assert(!res);
22     assert(res.error == 42);
23 }

Meta