err

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

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

Examples

// implicit void value type
{
    auto res = err("foo");
    static assert(is(typeof(res) == Expected!(void, string)));
    assert(!res);
    assert(res.error == "foo");
}

// bool
{
    auto res = err!int("42");
    static assert(is(typeof(res) == Expected!(int, string)));
    assert(!res);
    assert(res.error == "42");
}

// other error type
{
    auto res = err!bool(42);
    static assert(is(typeof(res) == Expected!(bool, int)));
    assert(!res);
    assert(res.error == 42);
}

Meta